Skip to content

test: poll for shutDownCalled in startWithHttp401ShutsDownSink test (SDK-2028)#329

Merged
aaron-zeisler merged 1 commit intomainfrom
aaronz/SDK-2028/race-condition-in-test
Mar 17, 2026
Merged

test: poll for shutDownCalled in startWithHttp401ShutsDownSink test (SDK-2028)#329
aaron-zeisler merged 1 commit intomainfrom
aaronz/SDK-2028/race-condition-in-test

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Mar 16, 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

Describe the solution you've provided

The startWithHttp401ShutsDownSink 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 calling dataSourceUpdateSink.shutDown(). The test thread can resume and assert shutDownCalled before the background thread reaches the shutDown() call.

This PR adds a short polling loop (up to 1 second, checking every 10ms) to wait for shutDownCalled to become true before asserting. This is a test-only change — no production code is modified.

Key review points:

  • shutDownCalled is declared volatile in MockDataSourceUpdateSink (line 141 of MockComponents.java), so cross-thread visibility is guaranteed
  • The 1-second timeout is generous for what should complete in microseconds; the 10ms poll interval avoids busy-waiting
  • Sibling tests that assert assertFalse(shutDownCalled) are not affected by this race since shutDown() is never called in those code paths

Describe alternatives you've considered

Approach 2 (not used): Reorder production code in StreamingDataSource.onError() to call shutDown() before resultCallback.onError(). This would fix the root cause but changes production behavior and carries more risk. Per team discussion, Approach 1 (test-only fix) was chosen as the safer option.

Additional context

The Android SDK is required to compile/run tests locally, so this change relies on CI for validation.

Link to Devin session: https://app.devin.ai/sessions/c61d7f41a5ec43208840f81363097b09


Note

Low Risk
Low risk test-only change that adds a short wait to avoid a race between the background thread reporting the error and shutting down the update sink.

Overview
Fixes a flaky StreamingDataSourceTest.startWithHttp401ShutsDownSink by waiting (up to 1s, polling) for dataSourceUpdateSink.shutDownCalled to become true before asserting.

No production behavior changes; this only adjusts the test’s timing expectations for the async shutdown path after an HTTP 401.

Written by Cursor Bugbot for commit 4ebcfc9. This will update automatically on new commits. Configure here.

…Sink test

The test was flaky because it asserted shutDownCalled immediately after
callback.awaitError() returned. Since the production code calls
resultCallback.onError() before dataSourceUpdateSink.shutDown(), the
background thread may not have reached shutDown() yet when the test
thread resumes.

Added a short polling loop (up to 1 second) to wait for shutDownCalled
to become true before asserting, eliminating the race condition.

Resolves SDK-2028

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
Copy link
Contributor Author

🤖 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
Copy link
Contributor Author

Adding label: devin-pr

@aaron-zeisler aaron-zeisler marked this pull request as ready for review March 16, 2026 18:30
@aaron-zeisler aaron-zeisler requested a review from a team as a code owner March 16, 2026 18:30
@aaron-zeisler aaron-zeisler changed the title fix: poll for shutDownCalled in startWithHttp401ShutsDownSink test (SDK-2028) test: poll for shutDownCalled in startWithHttp401ShutsDownSink test (SDK-2028) Mar 16, 2026
@aaron-zeisler aaron-zeisler merged commit b8c2f2a into main Mar 17, 2026
11 checks passed
@aaron-zeisler aaron-zeisler deleted the aaronz/SDK-2028/race-condition-in-test branch March 17, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants