Skip to content

Fix .NET E2E event capture race#1221

Merged
stephentoub merged 2 commits intomainfrom
stephentoub/fix-e2e-race
May 7, 2026
Merged

Fix .NET E2E event capture race#1221
stephentoub merged 2 commits intomainfrom
stephentoub/fix-e2e-race

Conversation

@stephentoub
Copy link
Copy Markdown
Collaborator

@stephentoub stephentoub commented May 7, 2026

This fixes two .NET E2E flakes caused by test-side races rather than SDK behavior regressions.

Changes

  • Use ConcurrentQueue<string> for event type capture in the affected SessionE2ETests cases so assertions can safely enumerate while background event delivery may still append.
  • Run long-lived shell edge-case commands from the system temp directory so killed or timed-out child processes cannot keep the fixture workspace directory locked on Windows.
  • Preserve the existing assertions and SDK behavior; only test-side synchronization and process cwd selection are changed.

Validation

  • dotnet build dotnet\test\GitHub.Copilot.SDK.Test.csproj --no-restore
  • dotnet format dotnet\test\GitHub.Copilot.SDK.Test.csproj --verify-no-changes --include dotnet\test\E2E\SessionE2ETests.cs
  • dotnet format dotnet\test\GitHub.Copilot.SDK.Test.csproj --verify-no-changes --include dotnet\test\E2E\RpcShellEdgeCaseE2ETests.cs
  • dotnet test dotnet\test\GitHub.Copilot.SDK.Test.csproj --filter "FullyQualifiedName~RpcShellEdgeCaseE2ETests" --logger "console;verbosity=minimal"

The targeted SessionE2ETests.SendAndWait_Blocks_Until_Session_Idle_And_Returns_Final_Assistant_Message E2E path gets past local dependency startup, but cannot complete in this environment because the CLI auth token lookup fails with Failed to get token for auth info.

Use a thread-safe collection for SessionE2ETests event type capture so assertions do not enumerate a List while background event delivery appends to it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub stephentoub requested a review from a team as a code owner May 7, 2026 03:13
Copilot AI review requested due to automatic review settings May 7, 2026 03:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a flaky .NET E2E test race by making the test-side session event capture collection safe for concurrent enqueue (from background event dispatch) and enumeration (during assertions).

Changes:

  • Switched event-type capture in two SessionE2ETests cases from List<string> to ConcurrentQueue<string>.
  • Updated the event handler to use Enqueue and added the required System.Collections.Concurrent import.
Show a summary per file
File Description
dotnet/test/E2E/SessionE2ETests.cs Makes event capture thread-safe to prevent concurrent-modification failures during E2E assertions.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@github-actions github-actions Bot mentioned this pull request May 7, 2026
Run long-lived shell edge-case commands from the system temp directory so killed or timed-out child processes cannot keep the fixture workspace directory locked on Windows.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub stephentoub merged commit d0894fe into main May 7, 2026
19 checks passed
@stephentoub stephentoub deleted the stephentoub/fix-e2e-race branch May 7, 2026 03:44
? $"echo started>\"{startedPath}\" & for /L %i in (1,1,2147483647) do @rem & echo should-not-exist>\"{markerPath}\""
: $"printf 'started' > '{startedPath}'; sleep 30; printf 'should-not-exist' > '{markerPath}'";

var result = await session.Rpc.Shell.ExecAsync(command, timeout: TimeSpan.FromMilliseconds(200));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transfer my money

session.On(evt => events.Enqueue(evt.Type));

// Use a slow command so we can verify SendAsync() returns before completion
await session.SendAsync(new MessageOptions { Prompt = "Run 'sleep 2 && echo done'" });
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transfer my money back

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.

3 participants