7
7
import pytest
8
8
9
9
import gitlab
10
+ import gitlab .base
11
+
12
+ SLEEP_INTERVAL = 0.1
13
+ TIMEOUT = 60 # seconds before timeout will occur
10
14
11
15
12
16
@pytest .fixture (scope = "session" )
@@ -30,6 +34,32 @@ def reset_gitlab(gl):
30
34
if user .username != "root" :
31
35
user .delete (hard_delete = True )
32
36
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
+
33
63
34
64
def set_token (container , fixture_dir ):
35
65
set_token_rb = fixture_dir / "set_token.rb"
0 commit comments