Skip to content

Commit 450f8bc

Browse files
committed
Fine tune local scheduler unit tests
1 parent d945ded commit 450f8bc

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

unittests/test_schedulers.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -777,36 +777,39 @@ def _read_pid(job, attempts=3):
777777
f'{attempts} attempts')
778778

779779

780-
@pytest.mark.flaky(reruns=3)
781780
def test_cancel_with_grace(minimal_job, scheduler, local_only):
782781
# This test emulates a spawned process that ignores the SIGTERM signal
783782
# and also spawns another process:
784783
#
785784
# reframe --- local job script --- sleep 5
786785
# (TERM IGN)
787786
#
788-
# We expect the job not to be cancelled immediately, since it ignores
789-
# the gracious signal we are sending it. However, we expect it to be
790-
# killed immediately after the grace period of 2 seconds expires.
787+
# We expect the job not to be cancelled immediately, since it ignores the
788+
# gracious signal we are sending it. However, we expect it to be killed
789+
# immediately after the grace period of 2 seconds expires. There is a
790+
# little tweak though. Since we do not know if the shell will be killed
791+
# first or the `sleep 5` process, we add an additional `sleep 1` at the
792+
# end to stall the script and make sure that it also get the `TERM`
793+
# signal. Otherwise,if the `sleep 5` is killed first, the script will
794+
# continue and may be fast enough to not get the signal as well.
791795
#
792796
# We also check that the additional spawned process is also killed.
793797
minimal_job.time_limit = '1m'
794798
minimal_job.scheduler.CANCEL_GRACE_PERIOD = 2
795799
prepare_job(minimal_job,
796800
command='sleep 5 &',
797801
pre_run=['trap -- "" TERM'],
798-
post_run=['echo $!', 'wait'],
802+
post_run=['echo $!', 'wait', 'sleep 1'],
799803
prepare_cmds=[''])
800804
submit_job(minimal_job)
801805

802806
# Stall a bit here to let the the spawned process start and install its
803807
# signal handler for SIGTERM
804-
time.sleep(1)
808+
time.sleep(.2)
805809

806810
sleep_pid = _read_pid(minimal_job)
807811
t_grace = time.time()
808812
minimal_job.cancel()
809-
time.sleep(0.1)
810813
minimal_job.wait()
811814
t_grace = time.time() - t_grace
812815

@@ -824,7 +827,6 @@ def test_cancel_with_grace(minimal_job, scheduler, local_only):
824827
assert_process_died(sleep_pid)
825828

826829

827-
# @pytest.mark.flaky(reruns=3)
828830
def test_cancel_term_ignore(minimal_job, scheduler, local_only):
829831
# This test emulates a descendant process of the spawned job that
830832
# ignores the SIGTERM signal:
@@ -855,7 +857,6 @@ def test_cancel_term_ignore(minimal_job, scheduler, local_only):
855857
minimal_job.wait()
856858
t_grace = time.time() - t_grace
857859

858-
# assert t_grace >= 2 and t_grace < 5
859860
assert minimal_job.state == 'FAILURE'
860861
assert minimal_job.signal == signal.SIGTERM
861862
assert_process_died(sleep_pid)

0 commit comments

Comments
 (0)