- Notifications
You must be signed in to change notification settings - Fork675
chore: fixtures: after delete() wait to verify deleted#1784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
40 changes: 11 additions & 29 deletionstests/functional/conftest.py
This file contains hidden or 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 |
|---|---|---|
| @@ -9,9 +9,7 @@ | ||
| import gitlab | ||
| import gitlab.base | ||
| from tests.functional import helpers | ||
| @pytest.fixture(scope="session") | ||
| @@ -49,8 +47,6 @@ def reset_gitlab(gl): | ||
| logging.info(f"Marking for deletion user: {user.username!r}") | ||
| user.delete(hard_delete=True) | ||
| # Ensure everything has been reset | ||
| start_time = time.perf_counter() | ||
| @@ -60,15 +56,15 @@ def wait_for_list_size( | ||
| """Wait for the list() length to be no greater than expected maximum or fail | ||
| test if timeout is exceeded""" | ||
| logging.info(f"Checking {description!r} has no more than {max_length} items") | ||
| for count in range(helpers.MAX_ITERATIONS): | ||
| items = rest_manager.list() | ||
| if len(items) <= max_length: | ||
| break | ||
| logging.info( | ||
| f"Iteration: {count} Waiting for {description!r} items to be deleted: " | ||
| f"{[x.name for x in items]}" | ||
| ) | ||
| time.sleep(helpers.SLEEP_INTERVAL) | ||
| elapsed_time = time.perf_counter() - start_time | ||
| error_message = ( | ||
| @@ -280,10 +276,7 @@ def group(gl): | ||
| yield group | ||
| helpers.safe_delete(group) | ||
| @pytest.fixture(scope="module") | ||
| @@ -296,10 +289,7 @@ def project(gl): | ||
| yield project | ||
| helpers.safe_delete(project) | ||
| @pytest.fixture(scope="function") | ||
| @@ -327,7 +317,7 @@ def _merge_request(*, source_branch: str): | ||
| assert result is True, "sidekiq process should have terminated but did not" | ||
| project.refresh() # Gets us the current default branch | ||
| mr_branch =project.branches.create( | ||
| {"branch": source_branch, "ref": project.default_branch} | ||
| ) | ||
| # NOTE(jlvillal): Must create a commit in the new branch before we can | ||
| @@ -359,18 +349,13 @@ def _merge_request(*, source_branch: str): | ||
| time.sleep(0.5) | ||
| assert mr.merge_status != "checking" | ||
| to_delete.extend([mr, mr_branch]) | ||
nejch marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| return mr | ||
| yield _merge_request | ||
| for object in to_delete: | ||
| helpers.safe_delete(object) | ||
| @pytest.fixture(scope="module") | ||
| @@ -434,11 +419,8 @@ def user(gl): | ||
| yield user | ||
| # Use `hard_delete=True` or a 'Ghost User' may be created. | ||
| helpers.safe_delete(user, hard_delete=True) | ||
| @pytest.fixture(scope="module") | ||
39 changes: 39 additions & 0 deletionstests/functional/helpers.py
This file contains hidden or 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") |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.