Skip to content

Commit f26bf7d

Browse files
authored
Merge pull request #1783 from python-gitlab/jlvillal/sidekiq
chore: ensure reset_gitlab() succeeds
2 parents d65ce36 + 0aa0b27 commit f26bf7d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/functional/conftest.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import pytest
88

99
import gitlab
10+
import gitlab.base
11+
12+
SLEEP_INTERVAL = 0.1
13+
TIMEOUT = 60 # seconds before timeout will occur
1014

1115

1216
@pytest.fixture(scope="session")
@@ -30,6 +34,32 @@ def reset_gitlab(gl):
3034
if user.username != "root":
3135
user.delete(hard_delete=True)
3236

37+
max_iterations = int(TIMEOUT / SLEEP_INTERVAL)
38+
39+
# Ensure everything has been reset
40+
start_time = time.perf_counter()
41+
42+
def wait_for_maximum_list_length(
43+
rest_manager: gitlab.base.RESTManager, description: str, max_length: int = 0
44+
) -> None:
45+
"""Wait for the list() length to be no greater than expected maximum or fail
46+
test if timeout is exceeded"""
47+
for _ in range(max_iterations):
48+
if len(rest_manager.list()) <= max_length:
49+
break
50+
time.sleep(SLEEP_INTERVAL)
51+
assert len(rest_manager.list()) <= max_length, (
52+
f"Did not delete required items for {description}. "
53+
f"Elapsed_time: {time.perf_counter() - start_time}"
54+
)
55+
56+
wait_for_maximum_list_length(rest_manager=gl.projects, description="projects")
57+
wait_for_maximum_list_length(rest_manager=gl.groups, description="groups")
58+
wait_for_maximum_list_length(rest_manager=gl.variables, description="variables")
59+
wait_for_maximum_list_length(
60+
rest_manager=gl.users, description="users", max_length=1
61+
)
62+
3363

3464
def set_token(container, fixture_dir):
3565
set_token_rb = fixture_dir / "set_token.rb"

0 commit comments

Comments
 (0)