Skip to content

Commit e03b273

Browse files
author
Theofilos Manitaras
authored
Merge branch 'master' into dependabot/pip/sphinx-5.2.3
2 parents 518bb87 + e27bc5d commit e03b273

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

unittests/test_schedulers.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def prepare_job(job, command='hostname',
115115
pre_run = pre_run or ['echo prerun']
116116
post_run = post_run or ['echo postrun']
117117
prepare_cmds = prepare_cmds or ['echo prepare']
118-
with rt.module_use('unittests/modules'):
118+
with rt.module_use(test_util.TEST_MODULES):
119119
job.prepare(
120120
[
121121
*pre_run,
@@ -127,6 +127,11 @@ def prepare_job(job, command='hostname',
127127
)
128128

129129

130+
def submit_job(job):
131+
with rt.module_use(test_util.TEST_MODULES):
132+
job.submit()
133+
134+
130135
def assert_job_script_sanity(job):
131136
'''Assert the sanity of the produced script file.'''
132137
with open(job.script_filename) as fp:
@@ -386,7 +391,7 @@ def test_submit(make_job, exec_ctx):
386391
minimal_job = make_job(sched_access=exec_ctx.access)
387392
prepare_job(minimal_job)
388393
assert minimal_job.nodelist is None
389-
minimal_job.submit()
394+
submit_job(minimal_job)
390395
assert minimal_job.jobid is not None
391396
minimal_job.wait()
392397

@@ -401,14 +406,19 @@ def test_submit(make_job, exec_ctx):
401406
num_tasks_per_node = minimal_job.num_tasks_per_node or 1
402407
num_nodes = minimal_job.num_tasks // num_tasks_per_node
403408
assert num_nodes == len(minimal_job.nodelist)
404-
assert 0 == minimal_job.exitcode
409+
410+
# Handle the case where the exitcode was not reported by the scheduler
411+
assert minimal_job.exitcode is None or 0 == minimal_job.exitcode
412+
413+
with open(minimal_job.stderr) as stderr:
414+
assert not stderr.read().strip()
405415

406416

407417
def test_submit_timelimit(minimal_job, local_only):
408418
minimal_job.time_limit = '2s'
409419
prepare_job(minimal_job, 'sleep 10')
410420
t_job = time.time()
411-
minimal_job.submit()
421+
submit_job(minimal_job)
412422
assert minimal_job.jobid is not None
413423
minimal_job.wait()
414424
t_job = time.time() - t_job
@@ -430,7 +440,7 @@ def test_submit_job_array(make_job, slurm_only, exec_ctx):
430440
job = make_job(sched_access=exec_ctx.access)
431441
job.options = ['--array=0-1']
432442
prepare_job(job, command='echo "Task id: ${SLURM_ARRAY_TASK_ID}"')
433-
job.submit()
443+
submit_job(job)
434444
job.wait()
435445
if job.scheduler.registered_name == 'slurm':
436446
assert job.exitcode == 0
@@ -445,7 +455,7 @@ def test_cancel(make_job, exec_ctx):
445455
prepare_job(minimal_job, 'sleep 30')
446456
t_job = time.time()
447457

448-
minimal_job.submit()
458+
submit_job(minimal_job)
449459
minimal_job.cancel()
450460

451461
# We give some time to the local scheduler for the TERM signal to be
@@ -484,7 +494,7 @@ def test_wait_before_submit(minimal_job):
484494
def test_finished(make_job, exec_ctx):
485495
minimal_job = make_job(sched_access=exec_ctx.access)
486496
prepare_job(minimal_job, 'sleep 2')
487-
minimal_job.submit()
497+
submit_job(minimal_job)
488498
assert not minimal_job.finished()
489499
minimal_job.wait()
490500

@@ -498,7 +508,7 @@ def test_finished_before_submit(minimal_job):
498508
def test_finished_raises_error(make_job, exec_ctx):
499509
minimal_job = make_job(sched_access=exec_ctx.access)
500510
prepare_job(minimal_job, 'echo hello')
501-
minimal_job.submit()
511+
submit_job(minimal_job)
502512
minimal_job.wait()
503513

504514
# Emulate an error during polling and verify that it is raised correctly
@@ -555,7 +565,7 @@ def test_guess_num_tasks(minimal_job, scheduler):
555565
minimal_job.num_tasks = 0
556566
minimal_job._sched_flex_alloc_nodes = 'idle'
557567
prepare_job(minimal_job)
558-
minimal_job.submit()
568+
submit_job(minimal_job)
559569
minimal_job.wait()
560570
assert minimal_job.num_tasks == 1
561571
elif scheduler.registered_name in ('slurm', 'squeue'):
@@ -596,7 +606,7 @@ def state(self):
596606

597607
type(minimal_job).state = property(state)
598608
prepare_job(minimal_job, 'sleep 30')
599-
minimal_job.submit()
609+
submit_job(minimal_job)
600610
with pytest.raises(JobError,
601611
match='maximum pending time exceeded'):
602612
minimal_job.wait()
@@ -649,7 +659,7 @@ def test_cancel_with_grace(minimal_job, scheduler, local_only):
649659
pre_run=['trap -- "" TERM'],
650660
post_run=['echo $!', 'wait'],
651661
prepare_cmds=[''])
652-
minimal_job.submit()
662+
submit_job(minimal_job)
653663

654664
# Stall a bit here to let the the spawned process start and install its
655665
# signal handler for SIGTERM
@@ -696,7 +706,7 @@ def test_cancel_term_ignore(minimal_job, scheduler, local_only):
696706
pre_run=[''],
697707
post_run=[''],
698708
prepare_cmds=[''])
699-
minimal_job.submit()
709+
submit_job(minimal_job)
700710

701711
# Stall a bit here to let the the spawned process start and install its
702712
# signal handler for SIGTERM

0 commit comments

Comments
 (0)