Fix flaky test: use retry_asserts for observer event propagation#21417
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
Fix flaky test: use retry_asserts for observer event propagation#21417devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
The test_consume_events_ignores_non_in_flight_flow_runs and test_observer_consumes_cancelling_events tests relied on a fixed asyncio.sleep(0.2) for events to propagate through the websocket pipeline. Under CI load, this delay is insufficient, causing the callback to not be called in time. Replace the fixed sleep + immediate assertion with retry_asserts (max_attempts=5, delay=0.5) which retries the assertion up to 5 times with 0.5s between attempts, properly handling event propagation delays. Co-authored-by: apk <apk@cognition.ai> Co-Authored-By: bot_apk <apk@cognition.ai>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
desertaxle
approved these changes
Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes flaky
test_consume_events_ignores_non_in_flight_flow_runs(and the similartest_observer_consumes_cancelling_events) intests/test_observers.py.Root cause: Both tests emit events via
emit_event()and then assert the observer's callback was invoked after a fixedasyncio.sleep(0.2). Events must travel through the EventsWorker → websocket → PrefectEventSubscriber pipeline before reaching the observer's_consume_eventsloop, and 0.2 seconds is insufficient under CI load.Fix: Replace the fixed sleep + immediate assertion with the existing
retry_assertsutility (fromprefect._internal.testing), retrying up to 5 times with a 0.5 s delay between attempts. This is the same pattern used elsewhere in the test suite for eventual-consistency scenarios.Failed workflow run: https://github.com/PrefectHQ/prefect/actions/runs/23958380669
Checklist
<link to issue>"main.mint.json.Link to Devin session: https://app.devin.ai/sessions/ed3a43bb4a694ba79c59949174bd7d8c