Skip to content

test: poll for shutDownCalled in startWithHttp401PreventsSubsequentStart test#332

Draft
kinyoklion wants to merge 3 commits intomainfrom
devin/1773960729-fix-flaky-streaming-test
Draft

test: poll for shutDownCalled in startWithHttp401PreventsSubsequentStart test#332
kinyoklion wants to merge 3 commits intomainfrom
devin/1773960729-fix-flaky-streaming-test

Conversation

@kinyoklion
Copy link
Member

@kinyoklion kinyoklion commented Mar 19, 2026

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

Follow-up to #329, which fixed the same race condition in the sibling test startWithHttp401ShutsDownSink.

Describe the solution you've provided

The startWithHttp401PreventsSubsequentStart test is flaky due to a race condition in StreamingDataSource.onError(). The production code calls resultCallback.onError() before setting connection401Error = true and calling dataSourceUpdateSink.shutDown(). When callback1.awaitError() returns, the test thread can immediately call sds.start(callback2) before the background thread has set connection401Error, causing the second start to proceed and produce a callback — failing the assertion.

The fix adds a polling loop (up to 1s, checking every 10ms) that waits for dataSourceUpdateSink.shutDownCalled to become true before calling the second start(). Since shutDown() is called after connection401Error = true in the production code, this guarantees the flag is set. This matches the pattern already used in the startWithHttp401ShutsDownSink test (merged via #329).

Describe alternatives you've considered

Reordering the production code in StreamingDataSource.onError() to set connection401Error and call shutDown() before firing resultCallback.onError() would eliminate the race at the source. However, this is a test-only race condition and the production ordering (notify first, then clean up) is intentional, so fixing the test is the safer approach.

Additional context

Key review points:

  • Verify that shutDownCalled becoming true guarantees connection401Error is also true (it does — see StreamingDataSource.java lines 137-139, where connection401Error = true is set before shutDown() is called).
  • The 1-second polling timeout is well within the test class's 10-second global timeout (@Rule Timeout.seconds(10)).

CI verification

CI passed on 3 consecutive runs (initial push + 2 empty-commit re-triggers) to confirm the flake is resolved.

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


Open with Devin

…art test

The startWithHttp401PreventsSubsequentStart test is flaky due to a race
condition. In StreamingDataSource.onError(), the production code calls
resultCallback.onError() (which unblocks the test's callback.awaitError())
before setting connection401Error and calling dataSourceUpdateSink.shutDown().
The test thread can resume and call the second sds.start() before
connection401Error is set, causing the second start to proceed and produce
a callback.

This adds a short polling loop (up to 1 second, checking every 10ms) to
wait for shutDownCalled to become true before testing the second start,
matching the pattern used in the startWithHttp401ShutsDownSink fix.

Co-Authored-By: rlamb@launchdarkly.com <kingdewman@gmail.com>
@devin-ai-integration
Copy link
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 and CI monitoring

@devin-ai-integration devin-ai-integration bot added the devin-pr PRs created by Devin label Mar 19, 2026
devin-ai-integration bot and others added 2 commits March 19, 2026 23:03
Co-Authored-By: rlamb@launchdarkly.com <kingdewman@gmail.com>
Co-Authored-By: rlamb@launchdarkly.com <kingdewman@gmail.com>
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

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

Labels

devin-pr PRs created by Devin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant