def test_release_when_multiple_jobs_must_remain_computing(self): h = Host(0, "n", allow_sharing=True) h._allocate("j1") h._allocate("j2") h._start_computing() h._release("j1") assert h.is_computing and h.state == HostState.COMPUTING assert h.jobs and len(h.jobs) == 1 and h.jobs[0] == "j2"
def test_set_unavailable_must_return_to_last_state(self): h = Host(0, "n") h._allocate("job") h._start_computing() h._set_unavailable() assert h.is_unavailable and not h.is_computing h._set_available() assert h.is_computing and not h.is_unavailable
def test_start_computing_when_unavailable_must_raise(self): p1 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) h = Host(0, "n", pstates=[p1]) h._allocate("job") h._set_unavailable() with pytest.raises(SystemError) as excinfo: h._start_computing() assert "Unavailable" in str(excinfo.value)
def test_set_on_when_computing_must_raise(self): p1 = PowerState(0, PowerStateType.SLEEP, 10, 10) p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) p3 = PowerState(3, PowerStateType.SWITCHING_OFF, 50, 50) p4 = PowerState(4, PowerStateType.SWITCHING_ON, 75, 75) h = Host(0, "n", pstates=[p1, p3, p2, p4]) h._allocate("job") h._start_computing() with pytest.raises(SystemError) as excinfo: h._set_on() assert "switching on" in str(excinfo.value)
def test_set_computation_state_when_computing_valid(self): p1 = PowerState(0, PowerStateType.SLEEP, 10, 10) p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) p3 = PowerState(2, PowerStateType.COMPUTATION, 15, 150) p4 = PowerState(3, PowerStateType.SWITCHING_OFF, 50, 50) p5 = PowerState(4, PowerStateType.SWITCHING_ON, 75, 75) h = Host(0, "n", pstates=[p1, p3, p2, p4, p5]) h._allocate("job") h._start_computing() h._set_computation_pstate(2) assert h.pstate == p3 and h.power == p3.watt_full
def test_switch_off_computing_must_raise(self): p1 = PowerState(0, PowerStateType.SLEEP, 10, 10) p2 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) p3 = PowerState(2, PowerStateType.COMPUTATION, 1000, 10000) p4 = PowerState(3, PowerStateType.SWITCHING_OFF, 50, 50) p5 = PowerState(4, PowerStateType.SWITCHING_ON, 25, 25) h = Host(0, "n", pstates=[p1, p3, p2, p4, p5]) h._allocate("n") h._start_computing() with pytest.raises(RuntimeError) as excinfo: h._switch_off() assert "idle and free " in str(excinfo.value)
def test_release_valid(self): h = Host(0, "n") h._allocate("job") h._start_computing() h._release("job") assert h.is_idle and h.state == HostState.IDLE and not h.jobs
def test_start_computing_without_job_must_raise(self): h = Host(0, "n") with pytest.raises(SystemError) as excinfo: h._start_computing() assert "allocated" in str(excinfo.value)
def test_start_computing_valid(self): p1 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) h = Host(0, "n", pstates=[p1]) h._allocate("job") h._start_computing() assert h.is_computing and h.state == HostState.COMPUTING
def test_power_computing_state(self): p1 = PowerState(1, PowerStateType.COMPUTATION, 10, 100) h = Host(0, "n", pstates=[p1]) h._allocate("job") h._start_computing() assert h.power == 100 and h.is_computing