Skip to content

chore: ensure reset_gitlab() succeeds #1783

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/functional/conftest.py
Original file line number Diff line number Diff line change
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