Skip to content

Add tests for AsyncConsumerDataProcessor exception handling race condition - #6899

Closed
Youssef Fahmy (Youssef1313) with Copilot wants to merge 3 commits into
dev/ygerges/avoid-blockingfrom
copilot/sub-pr-6887
Closed

Youssef Fahmy (Youssef1313) with Copilot wants to merge 3 commits into
dev/ygerges/avoid-blockingfrom
copilot/sub-pr-6887

Conversation

Copilot AI commented Nov 7, 2025 •

Copy link
Copy Markdown
Contributor

Adds test coverage for AsyncConsumerDataProcessor exception handling, specifically the race condition scenario where an exception occurs during ConsumeAsync before _totalPayloadProcessed is incremented.

Tests Added

  • Exception propagation: Verifies DrainDataAsync rethrows exceptions from consumers
  • Race condition scenario: Tests the critical path where _consumerState.SetException() prevents exception loss when drain checks payload counts before the finally block increments counters (lines 68-71 in AsyncConsumerDataProcessor.netstandard.cs)
  • Multiple items with failure: Validates exception handling when processing batches
  • Happy path: Confirms normal operation returns correct counts

Implementation Notes

  • Thread-safe counters using Interlocked.Increment in test consumers
  • No fixed delays; relies on DrainDataAsync internal polling for deterministic behavior
  • Conditional compilation for netstandard builds only (#if !NETCOREAPP)
// Tests this code path:
catch (Exception ex) when (ex is not OperationCanceledException)
{
    // Without this, race condition between drain check and finally block
    // could lose the exception
    _consumerState.SetException(ex);
    throw;
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI commented Nov 7, 2025

Copy link
Copy Markdown
Contributor Author

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 37bvsblobprodcus311.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/11.0.0-beta.25553.1.txt (dns block)
    • Triggering command: dotnet build test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csproj -c Release --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Add tests for AsyncConsumerDataProcessor based on review feedback Add tests for AsyncConsumerDataProcessor exception handling race condition Nov 7, 2025
@Youssef1313
Youssef Fahmy (Youssef1313) deleted the copilot/sub-pr-6887 branch November 7, 2025 11:20
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