Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1784 from python-gitlab/jlvillal/sidekiq
chore: fixtures: after delete() wait to verify deleted
- Loading branch information
Showing
2 changed files
with
50 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import logging | ||
import time | ||
|
||
import pytest | ||
|
||
import gitlab.base | ||
|
||
SLEEP_INTERVAL = 0.5 | ||
TIMEOUT = 60 # seconds before timeout will occur | ||
MAX_ITERATIONS = int(TIMEOUT / SLEEP_INTERVAL) | ||
|
||
|
||
def safe_delete( | ||
object: gitlab.base.RESTObject, | ||
*, | ||
hard_delete: bool = False, | ||
) -> None: | ||
"""Ensure the object specified can not be retrieved. If object still exists after | ||
timeout period, fail the test""" | ||
manager = object.manager | ||
for index in range(MAX_ITERATIONS): | ||
try: | ||
object = manager.get(object.get_id()) | ||
except gitlab.exceptions.GitlabGetError: | ||
return | ||
|
||
if index: | ||
logging.info(f"Attempt {index+1} to delete {object!r}.") | ||
try: | ||
if hard_delete: | ||
object.delete(hard_delete=True) | ||
else: | ||
object.delete() | ||
except gitlab.exceptions.GitlabDeleteError: | ||
logging.info(f"{object!r} already deleted.") | ||
pass | ||
|
||
time.sleep(SLEEP_INTERVAL) | ||
pytest.fail(f"{object!r} was not deleted") |