test: fix flaky CanRestartStream test on .NET Framework#123
Merged
Conversation
…ramework On .NET Framework 4.6.2, cancelling a stream read can surface as an IOException rather than OperationCanceledException. This causes an Error event to fire before the Closed event during restart, which is a race condition that makes the test flaky. Add an allowSkip predicate overload to EventSink.ExpectActions that deterministically drains matching events from the blocking queue rather than using delays or timeouts. The CanRestartStream test uses this to skip Error events that are an expected side effect of cancellation on .NET Framework. Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Contributor
🤖 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:
|
tanderson-ld
approved these changes
Jul 1, 2026
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.
Summary
CanRestartStream(resetBackoff: False)flakes on net462 becauseRestart()cancels an in-flight HTTP request, and on .NET Framework the cancellation surfaces as anIOException(notOperationCanceledException). This causesEventSourceto fire anErrorevent beforeClosed, but the test only expectedClosed → Opened → MessageReceived.The fix adds a deterministic
allowSkippredicate overload toEventSink.ExpectActions:When waiting for the next expected action, any action matching
allowSkipis consumed from theBlockingCollectionand discarded — no sleeps or arbitrary timeouts. TheCanRestartStreamtest usesa => a.Kind == \"Error\"to skip the platform-specific cancellation error events after each restart.Link to Devin session: https://app.devin.ai/sessions/d88b0648af0f43babf666a735ae65524
Requested by: @kinyoklion
Note
Low Risk
Test-helper and test-only changes with no production EventSource behavior modified.
Overview
Stabilizes
CanRestartStreamon .NET Framework by tolerating extraErrorevents that can appear whenRestart()cancels an in-flight read and cancellation shows up asIOExceptioninstead ofOperationCanceledException.EventSink.ExpectActionsgains an optionalallowSkippredicate: while matching the expected sequence, any received action that satisfies the predicate is taken from the queue and ignored (no sleeps). The parameterless overload forwards toallowSkip: null. The restart loop usesa => a.Kind == "Error"so only the platform-specific cancellation errors are skipped;Closed→Opened→MessageReceivedassertions stay the same.Reviewed by Cursor Bugbot for commit 5c44e2b. Bugbot is set up for automated code reviews on this repo. Configure here.