@@ -209,7 +209,30 @@ def _check(
209209 return _check
210210
211211
212- @pytest .fixture
212+ def wait_for_sidekiq_function (
213+ * ,
214+ gl_instance : gitlab .Gitlab ,
215+ timeout : int = 30 ,
216+ step : float = 0.5 ,
217+ allow_fail : bool = False ,
218+ ) -> bool :
219+ """A function that is called to wait for the sidekiq process to finish. As
220+ opposed to the fixture."""
221+ for count in range (timeout ):
222+ time .sleep (step )
223+ busy = False
224+ processes = gl_instance .sidekiq .process_metrics ()["processes" ]
225+ for process in processes :
226+ if process ["busy" ]:
227+ busy = True
228+ if not busy :
229+ return True
230+ logging .info (f"sidekiq busy { count } of { timeout } " )
231+ assert allow_fail , "sidekiq process should have terminated but did not."
232+ return False
233+
234+
235+ @pytest .fixture (scope = "function" )
213236def wait_for_sidekiq (gl ):
214237 """
215238 Return a helper function to wait until there are no busy sidekiq processes.
@@ -218,18 +241,9 @@ def wait_for_sidekiq(gl):
218241 """
219242
220243 def _wait (timeout : int = 30 , step : float = 0.5 , allow_fail : bool = False ) -> bool :
221- for count in range (timeout ):
222- time .sleep (step )
223- busy = False
224- processes = gl .sidekiq .process_metrics ()["processes" ]
225- for process in processes :
226- if process ["busy" ]:
227- busy = True
228- if not busy :
229- return True
230- logging .info (f"sidekiq busy { count } of { timeout } " )
231- assert allow_fail , "sidekiq process should have terminated but did not."
232- return False
244+ return wait_for_sidekiq_function (
245+ gl_instance = gl , timeout = timeout , step = step , allow_fail = allow_fail
246+ )
233247
234248 return _wait
235249
@@ -529,6 +543,8 @@ def user(gl):
529543
530544 yield user
531545
546+ result = wait_for_sidekiq_function (gl_instance = gl , timeout = 60 )
547+ assert result is True , "sidekiq process should have terminated but did not"
532548 # Use `hard_delete=True` or a 'Ghost User' may be created.
533549 helpers .safe_delete (user , hard_delete = True )
534550
0 commit comments