Skip to content

Commit

Permalink
Merge pull request #1783 from python-gitlab/jlvillal/sidekiq
Browse files Browse the repository at this point in the history
chore: ensure reset_gitlab() succeeds
  • Loading branch information
nejch committed Dec 29, 2021
2 parents d65ce36 + 0aa0b27 commit f26bf7d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/functional/conftest.py
Expand Up @@ -7,6 +7,10 @@
import pytest

import gitlab
import gitlab.base

SLEEP_INTERVAL = 0.1
TIMEOUT = 60 # seconds before timeout will occur


@pytest.fixture(scope="session")
Expand All @@ -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"
Expand Down

0 comments on commit f26bf7d

Please sign in to comment.