1111import tempfile
1212import time
1313import unittest
14- from datetime import datetime
14+ from datetime import datetime , timedelta
1515
1616import reframe .core .runtime as rt
1717import reframe .utility .os_ext as os_ext
@@ -197,6 +197,21 @@ def test_guess_num_tasks(self):
197197 with pytest .raises (NotImplementedError ):
198198 self .testjob .guess_num_tasks ()
199199
200+ # Monkey patch `self._update_state` to simulate that the job is
201+ # pending on the queue for enough time so it can be canceled due
202+ # to exceeding the maximum pending time
203+ @fixtures .switch_to_user_runtime
204+ def test_submit_max_pending_time (self ):
205+ self .setup_user ()
206+ self .parallel_cmd = 'sleep 30'
207+ self .prepare ()
208+ self .testjob .scheduler ._update_state = self ._update_state
209+ self .testjob ._max_pending_time = timedelta (milliseconds = 50 )
210+ self .testjob .submit ()
211+ with pytest .raises (JobError ,
212+ match = 'maximum pending time exceeded' ):
213+ self .testjob .wait ()
214+
200215
201216class TestLocalJob (_TestJob , unittest .TestCase ):
202217 def assertProcessDied (self , pid ):
@@ -321,6 +336,10 @@ def test_guess_num_tasks(self):
321336 self .testjob .wait ()
322337 assert self .testjob .num_tasks == 1
323338
339+ def test_submit_max_pending_time (self ):
340+ pytest .skip ('the maximum pending time has no effect on the '
341+ 'local scheduler' )
342+
324343
325344class TestSlurmJob (_TestJob , unittest .TestCase ):
326345 @property
@@ -338,6 +357,9 @@ def sched_configured(self):
338357 def setup_user (self , msg = None ):
339358 super ().setup_user (msg = 'SLURM (with sacct) not configured' )
340359
360+ def _update_state (self , job ):
361+ job .state = 'PENDING'
362+
341363 def test_prepare (self ):
342364 self .setup_job ()
343365 super ().test_prepare ()
@@ -529,9 +551,12 @@ def test_prepare_no_cpus(self):
529551 assert self .expected_directives == found_directives
530552
531553 def test_submit_timelimit (self ):
532- # Skip this test for PBS, since we the minimum time limit is 1min
554+ # Skip this test for PBS, since the minimum time limit is 1min
533555 pytest .skip ("PBS minimum time limit is 60s" )
534556
557+ def test_submit_max_pending_time (self ):
558+ pytest .skip ('not implemented for the pbs scheduler' )
559+
535560
536561class TestTorqueJob (TestPbsJob ):
537562 @property
@@ -561,6 +586,12 @@ def test_submit_timelimit(self):
561586 # Skip this test for PBS, since we the minimum time limit is 1min
562587 pytest .skip ("Torque minimum time limit is 60s" )
563588
589+ def _update_state (self , job ):
590+ job .state = 'QUEUED'
591+
592+ def test_submit_max_pending_time (self ):
593+ _TestJob .test_submit_max_pending_time (self )
594+
564595
565596class TestSlurmFlexibleNodeAllocation (unittest .TestCase ):
566597 def create_dummy_nodes (obj ):
0 commit comments