Skip to content
Merged
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
40 changes: 32 additions & 8 deletions TUnit.Engine/TestDiscoveryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ public async Task<TestDiscoveryResult> DiscoverTests(string testSessionId, ITest

// Now invoke event receivers (registration phase)
// ITestRegisteredEventReceiver can access dependency information and any state set by After(TestDiscovery) hooks
foreach (var test in allTests)
{
await _testBuilderPipeline.InvokePostResolutionEventsAsync(test).ConfigureAwait(false);
}
await InvokePostResolutionEventsInParallelAsync(allTests).ConfigureAwait(false);

var filteredTests = isForExecution ? _testFilterService.FilterTests(filter, allTests) : allTests;

Expand Down Expand Up @@ -208,10 +205,7 @@ public async IAsyncEnumerable<AbstractExecutableTest> DiscoverTestsFullyStreamin

// Now invoke event receivers (registration phase)
// ITestRegisteredEventReceiver can access dependency information and any state set by After(TestDiscovery) hooks
foreach (var test in allTests)
{
await _testBuilderPipeline.InvokePostResolutionEventsAsync(test).ConfigureAwait(false);
}
await InvokePostResolutionEventsInParallelAsync(allTests).ConfigureAwait(false);

var independentTests = new List<AbstractExecutableTest>();
var dependentTests = new List<AbstractExecutableTest>();
Expand Down Expand Up @@ -291,6 +285,36 @@ private bool AreAllDependenciesSatisfied(AbstractExecutableTest test, Concurrent



private async Task InvokePostResolutionEventsInParallelAsync(List<AbstractExecutableTest> allTests)
{
if (allTests.Count < Building.ParallelThresholds.MinItemsForParallel)
{
foreach (var test in allTests)
{
await _testBuilderPipeline.InvokePostResolutionEventsAsync(test).ConfigureAwait(false);
}
return;
}

#if NET6_0_OR_GREATER
await Parallel.ForEachAsync(
allTests,
new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount },
async (test, _) =>
{
await _testBuilderPipeline.InvokePostResolutionEventsAsync(test).ConfigureAwait(false);
}
).ConfigureAwait(false);
#else
var tasks = new Task[allTests.Count];
for (var i = 0; i < allTests.Count; i++)
{
tasks[i] = _testBuilderPipeline.InvokePostResolutionEventsAsync(allTests[i]).AsTask();
}
await Task.WhenAll(tasks).ConfigureAwait(false);
#endif
}

public IEnumerable<TestContext> GetCachedTestContexts()
{
return _cachedTests.Select(static t => t.Context);
Expand Down
Loading