Fix flaky OpenAiSttService SSE test (deterministic progress)#11963
Merged
Conversation
TranscribeAsync_SseStream_AccumulatesDeltasAndReportsDoneSegments intermittently failed in the full (parallel) test run while passing in isolation. The service reports deltas/segments synchronously via IProgress<T>.Report while parsing the stream, but the test used the BCL Progress<T>, which posts callbacks to a SynchronizationContext / the thread pool instead of running them inline. Under full-suite parallelism the posted callbacks either arrived after the 2s WaitForAsync poll deadline or raced on the non-thread-safe List<T>s - both flaky. Use a synchronous IProgress<T> stub so callbacks run inline on the parse thread; the lists are then complete and ordered when TranscribeAsync returns, so the assertions run directly and the polling WaitForAsync helper is removed. Test-only change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
TranscribeAsync_SseStream_AccumulatesDeltasAndReportsDoneSegmentsintermittently failed in the full (parallel) test run while always passing in isolation.Root cause (test-only)
The service reports deltas/segments synchronously via
IProgress<T>.Reportwhile parsing the SSE stream (beforeTranscribeAsyncreturns). The test used the BCLProgress<T>, which doesn't run callbacks inline — it posts them to the capturedSynchronizationContext, or to the thread pool if none. The test then polledWaitForAsync(..., 2000ms)and asserted on plainList<>s. Under full-suite xUnit parallelism this flaked two ways:List<>.Production
Progress<T>(marshaling to the UI thread) is correct — this was purely a test artifact, and only this one test used the pattern.Fix
Use a tiny synchronous
IProgress<T>stub so callbacks run inline on the parse thread; the lists are complete and ordered whenTranscribeAsyncreturns, so assertions run directly and the pollingWaitForAsynchelper is removed.Verification
Ran the full UI suite 3×: 481/481 each time (previously intermittently 480/481), and the class 5× in isolation.
🤖 Generated with Claude Code