Skip to content

test: fix flaky test_request_queue_unlock_requests#786

Open
vdusek wants to merge 1 commit into
masterfrom
test/fix-flaky-request-queue-unlock
Open

test: fix flaky test_request_queue_unlock_requests#786
vdusek wants to merge 1 commit into
masterfrom
test/fix-flaky-request-queue-unlock

Conversation

@vdusek
Copy link
Copy Markdown
Contributor

@vdusek vdusek commented May 11, 2026

Summary

Fix this flaky CI run of test_request_queue_unlock_requests[sync], which failed with assert 2 == 3 on unlock_response.unlocked_count.

Root cause: the polling loop called list_and_lock_head repeatedly, which has the side effect of locking items. Across multiple iterations (due to eventual consistency on add_request) the total set of actually-locked requests no longer matched the last response's items count, so unlock_requests could report a different count than the test expected.

Fix: separate the two concerns — poll the read-only list_head until all 5 added requests are visible, then call list_and_lock_head(limit=3) exactly once. This removes the cross-iteration locking ambiguity.

Applied the same treatment to test_request_queue_list_and_lock_head, which shared the same racy polling pattern.

@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels May 11, 2026
@vdusek vdusek self-assigned this May 11, 2026
@github-actions github-actions Bot added this to the 140th sprint - Tooling team milestone May 11, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label May 11, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.73%. Comparing base (fa24a21) to head (85b27a5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #786      +/-   ##
==========================================
- Coverage   97.81%   97.73%   -0.09%     
==========================================
  Files          48       48              
  Lines        4860     4860              
==========================================
- Hits         4754     4750       -4     
- Misses        106      110       +4     
Flag Coverage Δ
integration 93.66% <ø> (-0.38%) ⬇️
unit 86.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek vdusek force-pushed the test/fix-flaky-request-queue-unlock branch 2 times, most recently from a1bb13f to 2ae6dfa Compare May 11, 2026 09:01
@vdusek vdusek requested a review from janbuchar May 11, 2026 09:03
@vdusek vdusek force-pushed the test/fix-flaky-request-queue-unlock branch from 2ae6dfa to 85b27a5 Compare May 11, 2026 14:42
Comment on lines 408 to +426
# Add multiple requests
for i in range(5):
await maybe_await(
rq_client.add_request({'url': f'https://example.com/lock-{i}', 'unique_key': f'lock-{i}'})
)

# Poll until requests are available for locking (eventual consistency)
lock_response: LockedRequestQueueHead | None = None
# Poll (without side effects) until all requests are visible. Using `list_and_lock_head` for polling
# would lock items across iterations, leading to an ambiguous count of actually-locked requests.
head_response: RequestQueueHead | None = None
for _ in range(5):
await maybe_sleep(1, is_async=is_async)
result = await maybe_await(rq_client.list_and_lock_head(limit=3, lock_duration=timedelta(seconds=60)))
assert isinstance(result, LockedRequestQueueHead)
lock_response = result
if len(lock_response.items) == 3:
result = await maybe_await(rq_client.list_head(limit=5))
assert isinstance(result, RequestQueueHead)
head_response = result
if len(head_response.items) == 5:
break

assert lock_response is not None
assert head_response is not None
assert len(head_response.items) == 5
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a helper function instead (ensure_queue_is_populated?), calling list_head in a test focused on list_and_lock_head gives off bad vibes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants