Skip to content

test: fix flaky CanRestartStream test on .NET Framework#123

Merged
kinyoklion merged 1 commit into
mainfrom
devin/1782923419-fix-flaky-restart-test
Jul 1, 2026
Merged

test: fix flaky CanRestartStream test on .NET Framework#123
kinyoklion merged 1 commit into
mainfrom
devin/1782923419-fix-flaky-restart-test

Conversation

@kinyoklion

@kinyoklion kinyoklion commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

CanRestartStream(resetBackoff: False) flakes on net462 because Restart() cancels an in-flight HTTP request, and on .NET Framework the cancellation surfaces as an IOException (not OperationCanceledException). This causes EventSource to fire an Error event before Closed, but the test only expected Closed → Opened → MessageReceived.

The fix adds a deterministic allowSkip predicate overload to EventSink.ExpectActions:

public void ExpectActions(Func<Action, bool> allowSkip, params Action[] expectedActions)

When waiting for the next expected action, any action matching allowSkip is consumed from the BlockingCollection and discarded — no sleeps or arbitrary timeouts. The CanRestartStream test uses a => 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 CanRestartStream on .NET Framework by tolerating extra Error events that can appear when Restart() cancels an in-flight read and cancellation shows up as IOException instead of OperationCanceledException.

EventSink.ExpectActions gains an optional allowSkip predicate: 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 to allowSkip: null. The restart loop uses a => a.Kind == "Error" so only the platform-specific cancellation errors are skipped; ClosedOpenedMessageReceived assertions stay the same.

Reviewed by Cursor Bugbot for commit 5c44e2b. Bugbot is set up for automated code reviews on this repo. Configure here.

…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>
@kinyoklion kinyoklion self-assigned this Jul 1, 2026
@devin-ai-integration

Copy link
Copy Markdown
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, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot added the devin-pr PR created by Devin label Jul 1, 2026
@kinyoklion kinyoklion marked this pull request as ready for review July 1, 2026 16:37
@kinyoklion kinyoklion requested a review from a team as a code owner July 1, 2026 16:37
@kinyoklion kinyoklion merged commit 5caf03b into main Jul 1, 2026
6 checks passed
@kinyoklion kinyoklion deleted the devin/1782923419-fix-flaky-restart-test branch July 1, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devin-pr PR created by Devin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants