Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions TUnit.Engine/Scheduling/TestScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ public async Task<bool> ScheduleAndExecuteAsync(
}
}

var executableTestsArray = executableTests.ToArray();
if (executableTestsArray.Length == 0)
if (executableTests.Count == 0)
{
await _logger.LogDebugAsync("No executable tests found after removing circular dependencies").ConfigureAwait(false);
return true;
Expand All @@ -131,7 +130,7 @@ public async Task<bool> ScheduleAndExecuteAsync(
_staticPropertyHandler.TrackStaticProperties();

// Group tests by their parallel constraints
var groupedTests = await _groupingService.GroupTestsByConstraintsAsync(executableTestsArray).ConfigureAwait(false);
var groupedTests = await _groupingService.GroupTestsByConstraintsAsync(executableTests).ConfigureAwait(false);

// Execute tests according to their grouping
await ExecuteGroupedTestsAsync(groupedTests, cancellationToken).ConfigureAwait(false);
Expand Down
11 changes: 7 additions & 4 deletions TUnit.Engine/Services/CircularDependencyDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal sealed class CircularDependencyDetector
var testList = tests as IList<AbstractExecutableTest> ?? tests.ToList();
var circularDependencies = new List<(AbstractExecutableTest Test, List<AbstractExecutableTest> DependencyChain)>();
var visitedStates = new Dictionary<string, VisitState>(capacity: testList.Count);
var pathBuffer = new List<AbstractExecutableTest>(4);

foreach (var test in testList)
{
Expand All @@ -27,12 +28,14 @@ internal sealed class CircularDependencyDetector
continue;
}

// Reuse path buffer for each test, making a copy when a cycle is found
pathBuffer.Clear();

// Typical cycle depth is small (2-5 tests), pre-size to 4
var path = new List<AbstractExecutableTest>(4);
if (HasCycleDfs(test, testList, visitedStates, path))
if (HasCycleDfs(test, testList, visitedStates, pathBuffer))
{
// Found a cycle - add all tests in the cycle to circular dependencies
var cycle = new List<AbstractExecutableTest>(path);
var cycle = new List<AbstractExecutableTest>(pathBuffer);
circularDependencies.Add((test, cycle));
}
}
Expand Down Expand Up @@ -87,4 +90,4 @@ private bool HasCycleDfs(

return false;
}
}
}
Loading