@@ -209,7 +209,30 @@ def _check(
209
209
return _check
210
210
211
211
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" )
213
236
def wait_for_sidekiq (gl ):
214
237
"""
215
238
Return a helper function to wait until there are no busy sidekiq processes.
@@ -218,18 +241,9 @@ def wait_for_sidekiq(gl):
218
241
"""
219
242
220
243
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
+ )
233
247
234
248
return _wait
235
249
@@ -529,6 +543,8 @@ def user(gl):
529
543
530
544
yield user
531
545
546
+ result = wait_for_sidekiq_function (gl_instance = gl , timeout = 60 )
547
+ assert result is True , "sidekiq process should have terminated but did not"
532
548
# Use `hard_delete=True` or a 'Ghost User' may be created.
533
549
helpers .safe_delete (user , hard_delete = True )
534
550
0 commit comments