@@ -184,6 +184,22 @@ def _wait(timeout=30, step=0.5):
184
184
return _wait
185
185
186
186
187
+ def wait_for_deleted (
188
+ * , pg_manager : gitlab .base .RESTManager , object_id : int , description : str
189
+ ) -> None :
190
+ """Ensure the object specified can not be retrieved. If object still exists after
191
+ timeout period, fail the test"""
192
+ max_iterations = int (TIMEOUT / SLEEP_INTERVAL )
193
+
194
+ for _ in range (max_iterations ):
195
+ try :
196
+ pg_manager .get (object_id )
197
+ except gitlab .exceptions .GitlabGetError :
198
+ return
199
+ time .sleep (SLEEP_INTERVAL )
200
+ pytest .fail (f"{ description } { object_id } was not deleted" )
201
+
202
+
187
203
@pytest .fixture (scope = "session" )
188
204
def gitlab_config (check_is_alive , docker_ip , docker_services , temp_dir , fixture_dir ):
189
205
config_file = temp_dir / "python-gitlab.cfg"
@@ -263,6 +279,7 @@ def group(gl):
263
279
"path" : f"group-{ _id } " ,
264
280
}
265
281
group = gl .groups .create (data )
282
+ group_id = group .id
266
283
267
284
yield group
268
285
@@ -271,6 +288,8 @@ def group(gl):
271
288
except gitlab .exceptions .GitlabDeleteError as e :
272
289
print (f"Group already deleted: { e } " )
273
290
291
+ wait_for_deleted (pg_manager = gl .groups , object_id = group_id , description = "Group" )
292
+
274
293
275
294
@pytest .fixture (scope = "module" )
276
295
def project (gl ):
@@ -279,6 +298,7 @@ def project(gl):
279
298
name = f"test-project-{ _id } "
280
299
281
300
project = gl .projects .create (name = name )
301
+ project_id = project .id
282
302
283
303
yield project
284
304
@@ -287,6 +307,10 @@ def project(gl):
287
307
except gitlab .exceptions .GitlabDeleteError as e :
288
308
print (f"Project already deleted: { e } " )
289
309
310
+ wait_for_deleted (
311
+ pg_manager = gl .projects , object_id = project_id , description = "Project"
312
+ )
313
+
290
314
291
315
@pytest .fixture (scope = "function" )
292
316
def merge_request (project , wait_for_sidekiq ):
@@ -358,6 +382,18 @@ def _merge_request(*, source_branch: str):
358
382
# Ignore if branch was already deleted
359
383
pass
360
384
385
+ for mr_iid , source_branch in to_delete :
386
+ wait_for_deleted (
387
+ pg_manager = project .mergerequests ,
388
+ object_id = mr_iid ,
389
+ description = "Project mergerequest" ,
390
+ )
391
+ wait_for_deleted (
392
+ pg_manager = project .branches ,
393
+ object_id = source_branch ,
394
+ description = "Project branch" ,
395
+ )
396
+
361
397
362
398
@pytest .fixture (scope = "module" )
363
399
def project_file (project ):
@@ -417,6 +453,7 @@ def user(gl):
417
453
password = "fakepassword"
418
454
419
455
user = gl .users .create (email = email , username = username , name = name , password = password )
456
+ user_id = user .id
420
457
421
458
yield user
422
459
@@ -426,6 +463,8 @@ def user(gl):
426
463
except gitlab .exceptions .GitlabDeleteError as e :
427
464
print (f"User already deleted: { e } " )
428
465
466
+ wait_for_deleted (pg_manager = gl .users , object_id = user_id , description = "User" )
467
+
429
468
430
469
@pytest .fixture (scope = "module" )
431
470
def issue (project ):
0 commit comments