@@ -2759,43 +2759,86 @@ def __enter__(self):
27592759 def __exit__ (self , type , value , traceback ):
27602760 pass
27612761
2762- # wait for lock to be removed, with 1 second interval of checking
2763- extra_args . append ( ' --wait-on-lock=1' )
2762+ # wait for lock to be removed, with 1 second interval of checking;
2763+ # check with both --wait-on-lock-interval and deprecated --wait-on-lock options
27642764
27652765 wait_regex = re .compile ("^== lock .*_software_toy_0.0.lock exists, waiting 1 seconds" , re .M )
27662766 ok_regex = re .compile ("^== COMPLETED: Installation ended successfully" , re .M )
27672767
2768- self .assertTrue (os .path .exists (toy_lock_path ))
2768+ test_cases = [
2769+ ['--wait-on-lock=1' ],
2770+ ['--wait-on-lock=1' , '--wait-on-lock-interval=60' ],
2771+ ['--wait-on-lock=100' , '--wait-on-lock-interval=1' ],
2772+ ['--wait-on-lock-limit=100' , '--wait-on-lock=1' ],
2773+ ['--wait-on-lock-limit=100' , '--wait-on-lock-interval=1' ],
2774+ ['--wait-on-lock-limit=-1' , '--wait-on-lock=1' ],
2775+ ['--wait-on-lock-limit=-1' , '--wait-on-lock-interval=1' ],
2776+ ]
27692777
2770- # use context manager to remove lock after 3 seconds
2771- with remove_lock_after (3 , toy_lock_path ):
2772- self .mock_stderr (True )
2773- self .mock_stdout (True )
2774- self .test_toy_build (extra_args = extra_args , verify = False , raise_error = True , testing = False )
2775- stderr , stdout = self .get_stderr (), self .get_stdout ()
2776- self .mock_stderr (False )
2777- self .mock_stdout (False )
2778+ for opts in test_cases :
27782779
2779- self .assertEqual (stderr , '' )
2780+ if any ('--wait-on-lock=' in x for x in opts ):
2781+ self .allow_deprecated_behaviour ()
2782+ else :
2783+ self .disallow_deprecated_behaviour ()
27802784
2781- wait_matches = wait_regex .findall (stdout )
2782- # we can't rely on an exact number of 'waiting' messages, so let's go with a range...
2783- self .assertTrue (len (wait_matches ) in range (2 , 5 ))
2785+ if not os .path .exists (toy_lock_path ):
2786+ mkdir (toy_lock_path )
27842787
2785- self .assertTrue (ok_regex .search (stdout ), "Pattern '%s' found in: %s" % (ok_regex .pattern , stdout ))
2788+ self .assertTrue (os .path .exists (toy_lock_path ))
2789+
2790+ all_args = extra_args + opts
2791+
2792+ # use context manager to remove lock after 3 seconds
2793+ with remove_lock_after (3 , toy_lock_path ):
2794+ self .mock_stderr (True )
2795+ self .mock_stdout (True )
2796+ self .test_toy_build (extra_args = all_args , verify = False , raise_error = True , testing = False )
2797+ stderr , stdout = self .get_stderr (), self .get_stdout ()
2798+ self .mock_stderr (False )
2799+ self .mock_stdout (False )
27862800
2787- # when there is no lock in place, --wait-on-lock has no impact
2788- self .assertFalse (os .path .exists (toy_lock_path ))
2801+ if any ('--wait-on-lock=' in x for x in all_args ):
2802+ self .assertTrue ("Use of --wait-on-lock is deprecated" in stderr )
2803+ else :
2804+ self .assertEqual (stderr , '' )
2805+
2806+ wait_matches = wait_regex .findall (stdout )
2807+ # we can't rely on an exact number of 'waiting' messages, so let's go with a range...
2808+ self .assertTrue (len (wait_matches ) in range (2 , 5 ))
2809+
2810+ self .assertTrue (ok_regex .search (stdout ), "Pattern '%s' found in: %s" % (ok_regex .pattern , stdout ))
2811+
2812+ # check use of --wait-on-lock-limit: if lock is never removed, we should give up when limit is reached
2813+ mkdir (toy_lock_path )
2814+ all_args = extra_args + ['--wait-on-lock-limit=3' , '--wait-on-lock-interval=1' ]
27892815 self .mock_stderr (True )
27902816 self .mock_stdout (True )
2791- self .test_toy_build (extra_args = extra_args , verify = False , raise_error = True , testing = False )
2817+ error_pattern = r"Maximum wait time for lock /.*toy_0.0.lock to be released reached: [0-9]+ sec >= 3 sec"
2818+ self .assertErrorRegex (EasyBuildError , error_pattern , self .test_toy_build , extra_args = all_args ,
2819+ verify = False , raise_error = True , testing = False )
27922820 stderr , stdout = self .get_stderr (), self .get_stdout ()
27932821 self .mock_stderr (False )
27942822 self .mock_stdout (False )
27952823
2796- self .assertEqual (stderr , '' )
2797- self .assertTrue (ok_regex .search (stdout ), "Pattern '%s' found in: %s" % (ok_regex .pattern , stdout ))
2798- self .assertFalse (wait_regex .search (stdout ), "Pattern '%s' not found in: %s" % (wait_regex .pattern , stdout ))
2824+ wait_matches = wait_regex .findall (stdout )
2825+ self .assertTrue (len (wait_matches ) in range (2 , 5 ))
2826+
2827+ # when there is no lock in place, --wait-on-lock* has no impact
2828+ remove_dir (toy_lock_path )
2829+ for opt in ['--wait-on-lock=1' , '--wait-on-lock-limit=3' , '--wait-on-lock-interval=1' ]:
2830+ all_args = extra_args + [opt ]
2831+ self .assertFalse (os .path .exists (toy_lock_path ))
2832+ self .mock_stderr (True )
2833+ self .mock_stdout (True )
2834+ self .test_toy_build (extra_args = all_args , verify = False , raise_error = True , testing = False )
2835+ stderr , stdout = self .get_stderr (), self .get_stdout ()
2836+ self .mock_stderr (False )
2837+ self .mock_stdout (False )
2838+
2839+ self .assertEqual (stderr , '' )
2840+ self .assertTrue (ok_regex .search (stdout ), "Pattern '%s' found in: %s" % (ok_regex .pattern , stdout ))
2841+ self .assertFalse (wait_regex .search (stdout ), "Pattern '%s' not found in: %s" % (wait_regex .pattern , stdout ))
27992842
28002843 # check for clean error on creation of lock
28012844 extra_args = ['--locks-dir=/' ]
0 commit comments