feat: implement DCOS source tree, tests, and build configuration
Complete implementation of the DCOS package including: - 40+ Python source files across agents, communication, core, learning, memory, protocols, utils - pyproject.toml build configuration - 102 unit tests across all subsystems - Fixed flake.nix (Python 3.12, proper dependencies, pyproject build) - Fixed .woodpecker.yml (correct paths, removed silent-fail flags) - Added .gitignore - Cleared stale pytest cache
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
Tests for ResourceAllocator.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from dcos.core.allocator import ResourceAllocator
|
||||
|
||||
|
||||
class TestResourceAllocator:
|
||||
def test_allocate(self):
|
||||
alloc = ResourceAllocator()
|
||||
assert alloc.allocate("agent_1", cpu=10.0, memory=256.0) is True
|
||||
|
||||
def test_allocate_over_limit(self):
|
||||
alloc = ResourceAllocator()
|
||||
# Total is 100 CPU, 1024 memory
|
||||
assert alloc.allocate("agent_1", cpu=60.0, memory=512.0) is True
|
||||
assert alloc.allocate("agent_2", cpu=50.0, memory=512.0) is False # over CPU
|
||||
|
||||
def test_release(self):
|
||||
alloc = ResourceAllocator()
|
||||
alloc.allocate("agent_1", cpu=10.0, memory=128.0)
|
||||
assert alloc.release("agent_1") is True
|
||||
assert alloc.release("nonexistent") is False
|
||||
|
||||
def test_utilization(self):
|
||||
alloc = ResourceAllocator()
|
||||
alloc.allocate("agent_1", cpu=25.0, memory=256.0)
|
||||
util = alloc.utilization()
|
||||
assert util["cpu"] == 0.25
|
||||
assert util["memory"] == 0.25
|
||||
|
||||
def test_get_allocation(self):
|
||||
alloc = ResourceAllocator()
|
||||
alloc.allocate("agent_1", cpu=10.0, memory=128.0)
|
||||
alloc_info = alloc.get_allocation("agent_1")
|
||||
assert alloc_info["cpu"] == 10.0
|
||||
Reference in New Issue
Block a user