Skip to content

[Bug]: Keyed scheduler runs sync tests serially on one thread, even with ParallelLimiter #7075

Closed

Description

@jerrosenberg

Bug report checklist

  • I've searched existing issues to ensure this isn't a duplicate
  • I've read the documentation and this isn't expected behavior
  • I'm using the latest version of TUnit

Description

Synchronous tests with distinct NotInParallel keys run one at a time on a single thread.
Suspected cause: the scheduler starts each test inside its loop without yielding. Adding await Task.Yield() works around it.

Expected Behavior

~2s total, all test run in parallel

Actual Behavior

~8s total, T1 through T4 run serially, while Y1 through Y4 correctly run in parallel

Steps to Reproduce

using TUnit.Core.Interfaces;

[assembly: ParallelLimiter<Limit8>]

public class Limit8 : IParallelLimit { public int Limit => 8; }

public class WithoutYield
{
    [Test, NotInParallel("a1")] public void T1() => Thread.Sleep(2000);
    [Test, NotInParallel("a2")] public void T2() => Thread.Sleep(2000);
    [Test, NotInParallel("a3")] public void T3() => Thread.Sleep(2000);
    [Test, NotInParallel("a4")] public void T4() => Thread.Sleep(2000);
}

public class WithYield
{
    [Before(Test)] public async Task YieldHook() => await Task.Yield();

    [Test, NotInParallel("b1")] public void Y1() => Thread.Sleep(2000);
    [Test, NotInParallel("b2")] public void Y2() => Thread.Sleep(2000);
    [Test, NotInParallel("b3")] public void Y3() => Thread.Sleep(2000);
    [Test, NotInParallel("b4")] public void Y4() => Thread.Sleep(2000);
}

Inspect the test report to show which tests run in parallel.

TUnit Version

1.75.0

.NET Version

.NET 10.0

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

Additional Context

No response

IDE-Specific Issue?

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

Activity

  1. added a commit that references this issue on Oct 18, 2026
    3bee707
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingperformancePerformance optimization

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions