Skip to content

Commit 196538b

Browse files
JohnVillalovosnejch
authored andcommitted
chore: simplify wait_for_sidekiq usage
Simplify usage of `wait_for_sidekiq` by putting the assert if it timed out inside the function rather than after calling it.
1 parent 6627a60 commit 196538b

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

tests/functional/api/test_lazy_objects.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def test_save_after_lazy_get_with_path(project, lazy_project):
2929

3030
def test_delete_after_lazy_get_with_path(gl, group, wait_for_sidekiq):
3131
project = gl.projects.create({"name": "lazy_project", "namespace_id": group.id})
32-
result = wait_for_sidekiq(timeout=60)
33-
assert result is True, "sidekiq process should have terminated but did not"
32+
wait_for_sidekiq(timeout=60)
3433
lazy_project = gl.projects.get(project.path_with_namespace, lazy=True)
3534
lazy_project.delete()
3635

tests/functional/api/test_merge_requests.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ def test_merge_request_should_remove_source_branch(
150150

151151
mr.merge(should_remove_source_branch=True)
152152

153-
result = wait_for_sidekiq(timeout=60)
154-
assert result is True, "sidekiq process should have terminated but did not"
153+
wait_for_sidekiq(timeout=60)
155154

156155
# Wait until it is merged
157156
mr_iid = mr.iid
@@ -162,8 +161,7 @@ def test_merge_request_should_remove_source_branch(
162161
time.sleep(0.5)
163162
assert mr.merged_at is not None
164163
time.sleep(0.5)
165-
result = wait_for_sidekiq(timeout=60)
166-
assert result is True, "sidekiq process should have terminated but did not"
164+
wait_for_sidekiq(timeout=60)
167165

168166
# Ensure we can NOT get the MR branch
169167
with pytest.raises(gitlab.exceptions.GitlabGetError):
@@ -195,8 +193,7 @@ def test_merge_request_large_commit_message(
195193
merge_commit_message=merge_commit_message, should_remove_source_branch=False
196194
)
197195

198-
result = wait_for_sidekiq(timeout=60)
199-
assert result is True, "sidekiq process should have terminated but did not"
196+
wait_for_sidekiq(timeout=60)
200197

201198
# Wait until it is merged
202199
mr_iid = mr.iid
@@ -235,8 +232,7 @@ def test_merge_request_merge_ref_should_fail(
235232
"commit_message": "Another commit in main branch",
236233
}
237234
)
238-
result = wait_for_sidekiq(timeout=60)
239-
assert result is True, "sidekiq process should have terminated but did not"
235+
wait_for_sidekiq(timeout=60)
240236

241237
# Check for non-existing merge_ref for MR with conflicts
242238
with pytest.raises(gitlab.exceptions.GitlabGetError):

tests/functional/api/test_users.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ def test_delete_user(gl, wait_for_sidekiq):
7070
)
7171

7272
new_user.delete()
73-
result = wait_for_sidekiq(timeout=60)
74-
assert result is True, "sidekiq process should have terminated but did not"
73+
wait_for_sidekiq(timeout=60)
7574

7675
assert new_user.id not in [user.id for user in gl.users.list()]
7776

tests/functional/conftest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def wait_for_sidekiq(gl):
224224
Use this with asserts for slow tasks (group/project/user creation/deletion).
225225
"""
226226

227-
def _wait(timeout=30, step=0.5):
227+
def _wait(timeout: int = 30, step: float = 0.5, allow_fail: bool = False) -> bool:
228228
for count in range(timeout):
229229
time.sleep(step)
230230
busy = False
@@ -235,6 +235,7 @@ def _wait(timeout=30, step=0.5):
235235
if not busy:
236236
return True
237237
logging.info(f"sidekiq busy {count} of {timeout}")
238+
assert allow_fail, "sidekiq process should have terminated but did not."
238239
return False
239240

240241
return _wait

0 commit comments

Comments
 (0)