@@ -209,7 +209,32 @@ 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+ process_metrics = gl_instance .sidekiq .process_metrics ()
225+ assert isinstance (process_metrics , dict )
226+ processes = process_metrics ["processes" ]
227+ for process in processes :
228+ if process ["busy" ]:
229+ busy = True
230+ if not busy :
231+ return True
232+ logging .info (f"sidekiq busy { count } of { timeout } " )
233+ assert allow_fail , "sidekiq process should have terminated but did not."
234+ return False
235+
236+
237+ @pytest .fixture (scope = "function" )
213238def wait_for_sidekiq (gl ):
214239 """
215240 Return a helper function to wait until there are no busy sidekiq processes.
@@ -218,18 +243,9 @@ def wait_for_sidekiq(gl):
218243 """
219244
220245 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
246+ return wait_for_sidekiq_function (
247+ gl_instance = gl , timeout = timeout , step = step , allow_fail = allow_fail
248+ )
233249
234250 return _wait
235251
@@ -529,6 +545,8 @@ def user(gl):
529545
530546 yield user
531547
548+ result = wait_for_sidekiq_function (gl_instance = gl , timeout = 60 )
549+ assert result is True , "sidekiq process should have terminated but did not"
532550 # Use `hard_delete=True` or a 'Ghost User' may be created.
533551 helpers .safe_delete (user , hard_delete = True )
534552
0 commit comments