def test_kill_job_must_sync_with_batsim(self, mocker): mocker.patch("batsim_py.simulator.KillJobBatsimRequest") s = SimulatorHandler() s.start("p", "w") e = BatsimEventAPI.get_job_submitted(res=1) msg = BatsimMessage(150, [JobSubmittedBatsimEvent(150, e['data'])]) mocker.patch.object(protocol.NetworkHandler, 'recv', return_value=msg) mocker.patch.object(batsim_py.jobs.Job, '_terminate') mocker.patch.object(batsim_py.resources.Host, '_release') s.proceed_time() mocker.patch("batsim_py.simulator.BatsimMessage") mocker.patch.object(batsim_py.jobs.Job, 'is_running', return_value=True) mocker.patch.object( protocol.NetworkHandler, 'recv', return_value=BatsimMessage(s.current_time, [])) job_id = s.jobs[0].id s.kill_job(job_id) assert s.jobs batsim_py.jobs.Job._terminate.assert_not_called() batsim_py.resources.Host._release.assert_not_called() simulator.KillJobBatsimRequest.assert_called_once_with( # type: ignore 150, job_id) assert simulator.NetworkHandler.send.call_count == 2
def test_kill_job_sim_not_running_must_raise(self): s = SimulatorHandler() with pytest.raises(RuntimeError) as excinfo: s.kill_job("1") assert "running" in str(excinfo.value)
def test_kill_job_not_found_must_raise(self): s = SimulatorHandler() s.start("p", "w") with pytest.raises(LookupError) as excinfo: s.kill_job("1") assert "job" in str(excinfo.value)
def test_kill_job_not_running_must_raise(self, mocker): mocker.patch("batsim_py.simulator.KillJobBatsimRequest") s = SimulatorHandler() s.start("p", "w") e = BatsimEventAPI.get_job_submitted(res=1) msg = BatsimMessage(150, [JobSubmittedBatsimEvent(150, e['data'])]) mocker.patch.object(protocol.NetworkHandler, 'recv', return_value=msg) s.proceed_time() with pytest.raises(RuntimeError) as excinfo: s.kill_job(s.jobs[0].id) assert "not running" in str(excinfo.value)