Skip to content

[Bug]: concurrency bug with Microsoft.Testing.Platform #4756

@dbulic

Description

@dbulic

Description

Running dotnet test (enabled MTP in global.json). It crashes in one specific project in the solution and in no others. I didn't manage to find the difference between this and other projects in the way we have set up tests.

Expected Behavior

Well, not to crash.

Actual Behavior

I am getting the same crash in dotnet test, VS 2026, and Rider 2026.1 EAP 3.
Noticing that if I run a smaller number of tests, it will run as expected. Increasing the number of tests running in parallel will sometimes have all test passing, sometimes trigger this crash. Selecting even more tests to run in parallel will reliably crash TUnit every time.
The same is happening with the latest v1.13.56, as was with v1.12.139.

Steps to Reproduce

Running dotnet test on solution, or running "Run all tests" on my Parser.MySql.UnitTests project.

TUnit Version

1.13.56

.NET Version

.NET 10.0

Operating System

Windows

IDE / Test Runner

JetBrains Rider

Error Output / Stack Trace

src\Semantic\Parser.UnitTests\MySql\bin\Debug\net10.0\Parser.MySql.UnitTests.dll (net10.0|x64) failed (3s 653ms)
Exit code: -532462766
  Error output: Unhandled exception. TUnit.Assertions.Exceptions.AssertionException: Expected to be empty, because Syntax error at offset 6, line 1 --> @gvar=1
  but collection contains items: [6-13 (7 chars)]

  at Assert.That(unit.SyntaxErrors).IsEmpty().Because("Syntax error at offset 6, line 1 --> @gvar=1")
     at TUnit.Assertions.Core.Assertion`1.ThrowOrAccumulateFailure(AssertionResult result)
     at TUnit.Assertions.Core.Assertion`1.ExecuteCoreAsync()
     at TUnit.Assertions.Core.Assertion`1.AssertAsync()
     at Parser.MySql.UnitTests.BaseMySqlLexerTests.GetStatementsAsync(String script) in C:\Dev\Tests\src\Semantic\Parser.UnitTests\MySql\BaseMySqlLexerTests.cs:line 39
     at Parser.MySql.UnitTests.BaseMySqlLexerTests.GetStatementAsync[T](String script) in C:\Dev\Tests\src\Semantic\Parser.UnitTests\MySql\BaseMySqlLexerTests.cs:line 25
     at Parser.MySql.UnitTests.Statements.IdentifierTest.<InvalidVar>b__2_0() in C:\Dev\Tests\src\Semantic\Parser.UnitTests\MySql\Statements\Identifier.cs:line 29
     at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__124_1(Object state)
     at System.Threading.QueueUserWorkItemCallback.Execute()
     at System.Threading.ThreadPoolWorkQueue.Dispatch()
     at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
     at System.Threading.Thread.StartCallback()
  Unhandled exception. System.Threading.SemaphoreFullException: Adding the specified count to the semaphore would cause it to exceed its maximum count.
     at System.Threading.SemaphoreSlim.Release(Int32 releaseCount)
     at Microsoft.Testing.Platform.Requests.SemaphoreSlimRequestCompleteNotifier.Complete() in /_/src/Platform/Microsoft.Testing.Platform/Requests/SemaphoreSlimRequestCompleteNotifier.cs:line 14
     at Microsoft.Testing.Platform.Extensions.TestFramework.ExecuteRequestContext.Complete() in /_/src/Platform/Microsoft.Testing.Platform/TestFramework/ExecuteRequestContext.cs:line 55
     at TUnit.Engine.Framework.TUnitTestFramework.ExecuteRequestAsync(ExecuteRequestContext context)
     at TUnit.Engine.Framework.TUnitTestFramework.ExecuteRequestAsync(ExecuteRequestContext context)
     at Microsoft.Testing.Platform.Requests.TestHostTestFrameworkInvoker.ExecuteRequestAsync(ITestFramework testFramework, TestExecutionRequest request, IMessageBus messageBus, CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TestHostTestFrameworkInvoker.cs:line 92
     at Microsoft.Testing.Platform.Requests.TestHostTestFrameworkInvoker.ExecuteAsync(ITestFramework testFramework, ClientInfo client, CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TestHostTestFrameworkInvoker.cs:line 73
     at Microsoft.Testing.Platform.Hosts.CommonHost.ExecuteRequestAsync(ProxyOutputDevice outputDevice, ITestSessionContext testSessionInfo, ServiceProvider serviceProvider, BaseMessageBus baseMessageBus, ITestFramework testFramework, ClientInfo client) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 166
     at Microsoft.Testing.Platform.Hosts.ConsoleTestHost.InternalRunAsync(CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ConsoleTestHost.cs:line 85
     at Microsoft.Testing.Platform.Hosts.ConsoleTestHost.InternalRunAsync(CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ConsoleTestHost.cs:line 117
     at Microsoft.Testing.Platform.Hosts.CommonHost.RunTestAppAsync(IPlatformOpenTelemetryService platformOTelService, CancellationToken testApplicationCancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 130
     at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 60
     at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 68
     at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 83
     at Microsoft.Testing.Platform.Builder.TestApplication.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs:line 223
     at Parser.MySql.UnitTests.MicrosoftTestingPlatformEntryPoint.Main(String[] args) in C:\Dev\Tests\src\Semantic\Parser.UnitTests\MySql\obj\Debug\net10.0\MicrosoftTestingPlatformEntryPoint.cs:line 18
     at Parser.MySql.UnitTests.MicrosoftTestingPlatformEntryPoint.<Main>(String[] args)

Additional Context

Sorry I can't provide a test repo because this relies on complex code we are testing. Tests themselves are quite simple.

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions