Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd87d6b1

Browse files
chore: make reset_gitlab() better
Saw issues in the CI where reset_gitlab() would fail. It would fail todelete the group that is created when GitLab starts up. Extending thetimeout didn't fix the issue.Changed the code to use the new `helpers.safe_delete()` function.Which will delete the resource and then make sure it is deleted beforereturning.Also added some logging functionality that can be seen if logging isturned on in pytest.
1 parent916b1db commitd87d6b1

File tree

1 file changed

+17
-48
lines changed

1 file changed

+17
-48
lines changed

‎tests/functional/conftest.py

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,68 +17,37 @@ def fixture_dir(test_dir):
1717
returntest_dir/"functional"/"fixtures"
1818

1919

20-
defreset_gitlab(gl):
21-
# previously tools/reset_gitlab.py
20+
defreset_gitlab(gl:gitlab.Gitlab)->None:
21+
"""Delete resources (such as projects, groups, users) that shouldn't
22+
exist."""
2223
forprojectingl.projects.list():
23-
logging.info(f"Marking for deletion project:{project.path_with_namespace!r}")
2424
fordeploy_tokeninproject.deploytokens.list():
2525
logging.info(
26-
f"Marking for deletion token:{deploy_token.username!r} in "
26+
f"Deleting deploy token:{deploy_token.username!r} in "
2727
f"project:{project.path_with_namespace!r}"
2828
)
29-
deploy_token.delete()
30-
project.delete()
29+
helpers.safe_delete(deploy_token)
30+
logging.info(f"Deleting project:{project.path_with_namespace!r}")
31+
helpers.safe_delete(project)
3132
forgroupingl.groups.list():
32-
logging.info(f"Marking for deletion group:{group.full_path!r}")
3333
fordeploy_tokeningroup.deploytokens.list():
3434
logging.info(
35-
f"Marking for deletion token:{deploy_token.username!r} in "
35+
f"Deleting deploy token:{deploy_token.username!r} in "
3636
f"group:{group.path_with_namespace!r}"
3737
)
38-
deploy_token.delete()
39-
group.delete()
38+
helpers.safe_delete(deploy_token)
39+
logging.info(f"Deleting group:{group.full_path!r}")
40+
helpers.safe_delete(group)
4041
fortopicingl.topics.list():
41-
topic.delete()
42+
logging.info(f"Deleting topic:{topic.name!r}")
43+
helpers.safe_delete(topic)
4244
forvariableingl.variables.list():
43-
logging.info(f"Marking for deletion variable:{variable.key!r}")
44-
variable.delete()
45+
logging.info(f"Deleting variable:{variable.key!r}")
46+
helpers.safe_delete(variable)
4547
foruseringl.users.list():
4648
ifuser.username!="root":
47-
logging.info(f"Marking for deletion user:{user.username!r}")
48-
user.delete(hard_delete=True)
49-
50-
# Ensure everything has been reset
51-
start_time=time.perf_counter()
52-
53-
defwait_for_list_size(
54-
rest_manager:gitlab.base.RESTManager,description:str,max_length:int=0
55-
)->None:
56-
"""Wait for the list() length to be no greater than expected maximum or fail
57-
test if timeout is exceeded"""
58-
logging.info(f"Checking{description!r} has no more than{max_length} items")
59-
forcountinrange(helpers.MAX_ITERATIONS):
60-
items=rest_manager.list()
61-
iflen(items)<=max_length:
62-
break
63-
logging.info(
64-
f"Iteration:{count} Waiting for{description!r} items to be deleted: "
65-
f"{[x.nameforxinitems]}"
66-
)
67-
time.sleep(helpers.SLEEP_INTERVAL)
68-
69-
elapsed_time=time.perf_counter()-start_time
70-
error_message= (
71-
f"More than{max_length}{description!r} items still remaining and timeout "
72-
f"({elapsed_time}) exceeded:{[x.nameforxinitems]}"
73-
)
74-
iflen(items)>max_length:
75-
logging.error(error_message)
76-
assertlen(items)<=max_length,error_message
77-
78-
wait_for_list_size(rest_manager=gl.projects,description="projects")
79-
wait_for_list_size(rest_manager=gl.groups,description="groups")
80-
wait_for_list_size(rest_manager=gl.variables,description="variables")
81-
wait_for_list_size(rest_manager=gl.users,description="users",max_length=1)
49+
logging.info(f"Deleting user:{user.username!r}")
50+
helpers.safe_delete(user,hard_delete=True)
8251

8352

8453
defset_token(container,fixture_dir):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp