Skip to content

test: fix race condition in delayed failure event test#47

Merged
kinyoklion merged 4 commits into
mainfrom
devin/1780910394-fix-delayed-failure-test
Jun 8, 2026
Merged

test: fix race condition in delayed failure event test#47
kinyoklion merged 4 commits into
mainfrom
devin/1780910394-fix-delayed-failure-test

Conversation

@kinyoklion

@kinyoklion kinyoklion commented Jun 8, 2026

Copy link
Copy Markdown
Member

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

None.

Describe the solution you've provided

Three event emission tests (test_provider_emits_ready_event_when_immediately_ready, test_provider_emits_error_event_immediately_failed, test_provider_emits_error_event_delayed_failure) check a counter immediately after set_provider without waiting for the event to be dispatched. The OpenFeature SDK now dispatches provider events asynchronously, so these assertions fail.

The fix uses threading.Event with wait(timeout=5), matching the pattern already used by test_provider_emits_stale_event and test_provider_emits_configuration_event.

Describe alternatives you've considered

Could add time.sleep() calls, but event-based waiting is more robust and consistent with existing tests.

Additional context

All 66 tests pass consistently. Lint (mypy) also passes.

Link to Devin session: https://app.devin.ai/sessions/385a2c260fe8433ea7e6af74fcde903c
Requested by: @kinyoklion


Note

Low Risk
Test-only changes with no runtime or library behavior modified.

Overview
Fixes flaky provider lifecycle tests that assumed OpenFeature dispatches PROVIDER_READY / PROVIDER_ERROR synchronously on set_provider.

test_provider_emits_ready_event_when_immediately_ready, test_provider_emits_error_event_immediately_failed, and test_provider_emits_error_event_delayed_failure now wait on a threading.Event (with wait(timeout=5)) set from the handler before asserting the emission count, plus a short time.sleep(0.1) so the counter update is visible. Handlers were simplified (shared emission_count, thread_event.set()). This matches test_provider_emits_stale_event and test_provider_emits_configuration_event.

No production/provider code changes—tests only.

Reviewed by Cursor Bugbot for commit 0340a25. Bugbot is set up for automated code reviews on this repo. Configure here.

The test_provider_emits_error_event_delayed_failure test was checking the error
count immediately after set_provider without waiting for the delayed event timer
(0.1s) to fire. This caused a consistent test failure.

Use a threading.Event with a timeout, matching the pattern used by
test_provider_emits_stale_event and test_provider_emits_configuration_event.

Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot added the devin-pr Pull request created by Devin AI label Jun 8, 2026
Apply the same event-based wait fix to test_provider_emits_ready_event_when_immediately_ready
and test_provider_emits_error_event_immediately_failed. The OpenFeature SDK now
dispatches provider events asynchronously, so checking counts immediately after
set_provider is unreliable.

Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Comment thread tests/test_provider.py

with lock:
assert ld_provider_ready_count == 1
assert thread_event.wait(timeout=5)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is there some way we could make this more robust against duplicate emissions?

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.

Good call. Updated all three tests to track an emission_count alongside the threading.Event. After the event fires, a short time.sleep(0.1) allows any spurious duplicate emissions to arrive, then we assert the count is exactly 1.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

aside: Typically we would avoid sleeps, but I think in this arrangement they are fine. We aren't using the sleep to try to catch the event we care about, but just as some extra time to check we aren't getting extra events. Which there isn't an amazing way to test for, but I have seen it be a problem with open feature, and hence the original test shape.

devin-ai-integration Bot and others added 2 commits June 8, 2026 16:17
Each event test now tracks emission_count alongside the threading.Event.
After the event fires, a short sleep allows any duplicate emissions to
arrive before asserting the count is exactly 1.

Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
@kinyoklion kinyoklion marked this pull request as ready for review June 8, 2026 16:26
@kinyoklion kinyoklion requested a review from a team as a code owner June 8, 2026 16:26
@kinyoklion kinyoklion merged commit 82de51d into main Jun 8, 2026
14 checks passed
@kinyoklion kinyoklion deleted the devin/1780910394-fix-delayed-failure-test branch June 8, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devin-pr Pull request created by Devin AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants