diff options
author | Nejc Habjan <hab.nejc@gmail.com> | 2021-12-29 01:13:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-29 01:13:49 +0100 |
commit | f26bf7d3a86e4d5d1a43423476a46a381e62e8f9 (patch) | |
tree | 06ebaa2105de7e22e0dc3a1dda23c119276d7450 | |
parent | d65ce365ff69a6bec2aa8d306800f6f76cbef842 (diff) | |
parent | 0aa0b272a90b11951f900b290a8154408eace1de (diff) | |
download | gitlab-f26bf7d3a86e4d5d1a43423476a46a381e62e8f9.tar.gz |
Merge pull request #1783 from python-gitlab/jlvillal/sidekiq
chore: ensure reset_gitlab() succeeds
-rw-r--r-- | tests/functional/conftest.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index 625cff9..7c4e584 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -7,6 +7,10 @@ from subprocess import check_output import pytest import gitlab +import gitlab.base + +SLEEP_INTERVAL = 0.1 +TIMEOUT = 60 # seconds before timeout will occur @pytest.fixture(scope="session") @@ -30,6 +34,32 @@ def reset_gitlab(gl): if user.username != "root": user.delete(hard_delete=True) + max_iterations = int(TIMEOUT / SLEEP_INTERVAL) + + # Ensure everything has been reset + start_time = time.perf_counter() + + def wait_for_maximum_list_length( + rest_manager: gitlab.base.RESTManager, description: str, max_length: int = 0 + ) -> None: + """Wait for the list() length to be no greater than expected maximum or fail + test if timeout is exceeded""" + for _ in range(max_iterations): + if len(rest_manager.list()) <= max_length: + break + time.sleep(SLEEP_INTERVAL) + assert len(rest_manager.list()) <= max_length, ( + f"Did not delete required items for {description}. " + f"Elapsed_time: {time.perf_counter() - start_time}" + ) + + wait_for_maximum_list_length(rest_manager=gl.projects, description="projects") + wait_for_maximum_list_length(rest_manager=gl.groups, description="groups") + wait_for_maximum_list_length(rest_manager=gl.variables, description="variables") + wait_for_maximum_list_length( + rest_manager=gl.users, description="users", max_length=1 + ) + def set_token(container, fixture_dir): set_token_rb = fixture_dir / "set_token.rb" |