def test_stretch_with_walltime(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0, 100) j._submit(0) j._allocate([1]) j._start(10) j._terminate(20, jobs.JobState.COMPLETED_SUCCESSFULLY) assert j.stretch == j.waiting_time / j.walltime
def test_terminate_not_running_job_must_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) with pytest.raises(RuntimeError) as excinfo: j._terminate(10, jobs.JobState.COMPLETED_SUCCESSFULLY) assert 'running' in str(excinfo.value)
def test_runtime(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) j._start(0) j._terminate(10, jobs.JobState.COMPLETED_SUCCESSFULLY) assert j.runtime == 10
def test_turnaround_time(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) j._start(10) j._terminate(30, jobs.JobState.COMPLETED_SUCCESSFULLY) assert j.turnaround_time == j.waiting_time + j.runtime
def test_allocate_size_less_than_requested_must_raise(self): j = jobs.Job("1", "w", 3, jobs.DelayJobProfile("p", 100), 0) j._submit(0) with pytest.raises(ValueError) as excinfo: j._allocate([3, 2]) assert "hosts" in str(excinfo.value)
def test_slowdown(self): j = jobs.Job("1", "w", 2, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1, 2]) j._start(10) j._terminate(30, jobs.JobState.COMPLETED_SUCCESSFULLY) assert j.slowdown == max(1, j.turnaround_time / j.runtime)
def test_allocate_valid(self): alloc = [1] j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate(alloc) assert j.is_runnable and j.state == jobs.JobState.ALLOCATED assert j.allocation == alloc
def test_start_invalid_time_must_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(2) j._allocate([1]) with pytest.raises(ValueError) as excinfo: j._start(1) assert 'current_time' in str(excinfo.value)
def test_start_rejected_job_must_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._reject() with pytest.raises(RuntimeError) as excinfo: j._start(2) assert 'runnable' in str(excinfo.value)
def test_start_valid(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) j._start(2) assert j.is_running assert j.state == jobs.JobState.RUNNING assert j.start_time == 2
def test_terminate_invalid_time_must_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) j._start(2) with pytest.raises(ValueError) as excinfo: j._terminate(1, jobs.JobState.COMPLETED_SUCCESSFULLY) assert 'current_time' in str(excinfo.value)
def test_reject_allocated_job_must_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) with pytest.raises(RuntimeError) as excinfo: j._reject() assert 'queue' in str(excinfo.value)
def test_allocate_not_storage_job_with_mapping_must_raise(self): prof = jobs.DelayJobProfile("p", 100) alloc = [1] j = jobs.Job("1", "w", 1, prof, 0) j._submit(0) with pytest.raises(ValueError) as excinfo: j._allocate(alloc, {"b": 1}) assert "mapping" in str(excinfo.value)
def test_start_finished_job_must_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) j._start(1) j._terminate(2, jobs.JobState.COMPLETED_FAILED) with pytest.raises(RuntimeError) as excinfo: j._start(2) assert 'runnable' in str(excinfo.value)
def test_terminate_walltime_reached_valid(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) j._start(0) j._terminate(10, jobs.JobState.COMPLETED_WALLTIME_REACHED) assert j.is_finished assert j.state == jobs.JobState.COMPLETED_WALLTIME_REACHED assert j.stop_time == 10
def test_terminate_successfully_valid(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) j._start(0) j._terminate(10, jobs.JobState.COMPLETED_SUCCESSFULLY) assert j.is_finished assert j.state == jobs.JobState.COMPLETED_SUCCESSFULLY assert j.stop_time == 10
def test_reject_finished_job_must_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) j._start(0) j._terminate(10, jobs.JobState.COMPLETED_SUCCESSFULLY) with pytest.raises(RuntimeError) as excinfo: j._reject() assert 'queue' in str(excinfo.value)
def test_valid_instance(self): name, workload, res, subtime = "1", "w", 2, 1 profile = jobs.DelayJobProfile("p", 100) j = jobs.Job(name, workload, res, profile, subtime, user_id=22) assert j.name == name and j.workload == j.workload assert j.res == res and j.profile == profile assert j.subtime == subtime and j.state == jobs.JobState.UNKNOWN assert j.walltime is None and j.user_id == 22 and j.allocation is None assert j.start_time is None and j.stop_time is None
def test_terminate_with_invalid_final_state_must_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) j._start(0) with pytest.raises(ValueError) as excinfo: j._terminate(10, jobs.JobState.ALLOCATED) assert 'final_state' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: j._terminate(10, jobs.JobState.REJECTED) assert 'final_state' in str(excinfo.value)
def test_valid_instance(self): name = "n" repeat = random.randint(1, 10) profiles = [ jobs.DelayJobProfile("p1", 100), jobs.ParallelHomogeneousJobProfile("p2", 1, 2) ] p = jobs.ComposedJobProfile(name, profiles, repeat) assert p.name == name assert p.profiles == profiles assert p.repeat == repeat
def test_slowdown_when_not_finished_must_not_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) j._start(10) assert j.slowdown is None
def test_turnaround_time_when_not_finished_must_not_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) j._start(10) assert j.turnaround_time is None
def test_allocate_cannot_be_changed(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) with pytest.raises(RuntimeError): j._allocate([3])
def test_reject_job_submitted_valid(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._reject() assert j.state == jobs.JobState.REJECTED and j.is_rejected
def test_allocate_not_submitted_job_must_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) with pytest.raises(RuntimeError) as excinfo: j._allocate([3]) assert "queue" in str(excinfo.value)
def test_submit_valid(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) assert j.subtime == 0 assert j.state == jobs.JobState.SUBMITTED and j.is_submitted
def test_waiting_time_when_not_started_must_not_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) assert j.waiting_time is None
def test_waiting_time(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) j._allocate([1]) j._start(10) assert j.waiting_time == 10
def test_submit_submitted_job_must_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) j._submit(0) with pytest.raises(RuntimeError) as excinfo: j._submit(0) assert 'submitted' in str(excinfo.value)
def test_submit_invalid_time_must_raise(self): j = jobs.Job("1", "w", 1, jobs.DelayJobProfile("p", 100), 0) with pytest.raises(ValueError) as excinfo: j._submit(-1) assert 'subtime' in str(excinfo.value)