Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 6, 2025

The NotInParallel attribute's Order property was not being respected when applied to classes, causing tests to execute in incorrect order based on dependency graph topological sorting instead of the specified order.

Problem

When using NotInParallel with different Order values on classes, tests were executing in the wrong sequence:

[NotInParallel(Order = 2)]
public sealed class Test1
{
    [Test]
    public async Task TestCase1()
    {
        Console.WriteLine("Test 1");
    }
}

[NotInParallel(Order = 1)]
public sealed class Test2
{
    [Test]
    public Task TestCase2()
    {
        Console.WriteLine("Test 2");
        return Task.CompletedTask;
    }
}

Expected output (v0.25.21):

Test 2
Test 1

Actual output (v0.52.8):

Test 1
Test 2

Root Cause

The issue was in TestScheduler.cs where the ExecuteNotInParallelTestsAsync and ExecuteKeyedNotInParallelTestsAsync methods were sorting tests by the ExecutionPlan's topological order instead of respecting the NotInParallel attribute's Order property. While the priority queue correctly sorted tests by TestPriority (which includes the constraint order), this correct ordering was being overridden by a secondary sort based on ExecutionPlan order.

Solution

Modified the sorting logic in both methods to:

  1. Primary sort: Use the NotInParallel Order property from TestPriority
  2. Secondary sort: Use ExecutionPlan order only for dependency resolution when NotInParallel orders are equal

This preserves the intended execution order while maintaining dependency ordering capabilities for tests with the same NotInParallel order value.

Verification

Manual testing confirms the fix works correctly:

  • Tests now execute in the proper order: Test 2 (Order 1), Test 1 (Order 2), Test 3 (Order 3)
  • The change is minimal and surgical, affecting only the sorting logic
  • Dependency resolution is preserved as a secondary sort criteria

Fixes #2779.

Warning

Firewall rules blocked me from connecting to one or more addresses

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

  • aka.ms
    • Triggering command: curl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED (dns block)

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


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] NotInParallel broken for class Fix NotInParallel Order property not being respected for class-level attributes Aug 6, 2025
Copilot AI requested a review from thomhurst August 6, 2025 12:30
Copilot finished work on behalf of thomhurst August 6, 2025 12:30
@thomhurst thomhurst marked this pull request as ready for review August 6, 2025 14:51
Copilot AI temporarily deployed to Pull Requests August 6, 2025 14:52 Inactive
Copilot AI temporarily deployed to Pull Requests August 6, 2025 14:52 Inactive
Copilot AI temporarily deployed to Pull Requests August 6, 2025 14:52 Inactive
@thomhurst thomhurst merged commit 3c951f3 into main Aug 6, 2025
7 of 8 checks passed
@thomhurst thomhurst deleted the copilot/fix-2779 branch August 6, 2025 15:39
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.

NotInParallel broken for class

2 participants