test: poll for connection401Error in startWithHttp401PreventsSubsequentStart test#337
Draft
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
…ntStart test Co-Authored-By: Aaron Zeisler <azeisler@launchdarkly.com>
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:
|
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.
Requirements
Related issues
Follow-up to b8c2f2a which fixed the same race condition in the sibling test
startWithHttp401ShutsDownSink. This test was identified as the cause of the CI failure on PR #326.Describe the solution you've provided
The
startWithHttp401PreventsSubsequentStarttest is flaky due to a race condition inStreamingDataSource.onError(). The production code callsresultCallback.onError()(line 136, which unblocks the test'sawaitError()) before settingconnection401Error = true(line 138). The test thread can resume and callsds.start(callback2)before the background thread reaches line 138, causing the secondstart()to pass the!connection401Errorguard and produce an unexpected error callback.This PR adds a polling loop (up to 1 second, probing every 50ms) that waits for
connection401Errorto be set before making the final assertion. Sinceconnection401Erroris private, the loop probes by callingsds.start()and checking whether it's a no-op (no error produced).sds.start(probe)repeatedly whileconnection401Erroris not yet set. Each probe that slips through the guard will create a real connection to the test HTTP server and receive a 401. Verify you're comfortable with these transient side effects during the polling window.Describe alternatives you've considered
An alternative would be to fix the ordering in the production code (
StreamingDataSource.onError()) so thatconnection401Error = trueis set beforeresultCallback.onError()is called, eliminating the race at the source. This would be a cleaner fix, but the polling-loop-in-test approach is the established pattern in this codebase (seestartWithHttp401ShutsDownSinkandAssertHelpers.assertPolledFunctionReturnsValue), so this PR follows that convention.Additional context
Only one test file is changed; no production code is modified.
Link to Devin session: https://app.devin.ai/sessions/b09435a9a0094a57bf716742eeb865ff