diff --git a/TUnit.Engine/Services/TestExecution/TestCoordinator.cs b/TUnit.Engine/Services/TestExecution/TestCoordinator.cs index c7ea325f1b..29e444588b 100644 --- a/TUnit.Engine/Services/TestExecution/TestCoordinator.cs +++ b/TUnit.Engine/Services/TestExecution/TestCoordinator.cs @@ -47,11 +47,9 @@ public TestCoordinator( _eventReceiverOrchestrator = eventReceiverOrchestrator; } - public async ValueTask ExecuteTestAsync(AbstractExecutableTest test, CancellationToken cancellationToken) - { - await _executionGuard.TryStartExecutionAsync(test.TestId, + public ValueTask ExecuteTestAsync(AbstractExecutableTest test, CancellationToken cancellationToken) + => _executionGuard.TryStartExecutionAsync(test.TestId, () => ExecuteTestInternalAsync(test, cancellationToken)); - } private async ValueTask ExecuteTestInternalAsync(AbstractExecutableTest test, CancellationToken cancellationToken) { diff --git a/TUnit.Engine/Services/TestExecution/TestExecutionGuard.cs b/TUnit.Engine/Services/TestExecution/TestExecutionGuard.cs index 06ac0c688c..32fdc49a77 100644 --- a/TUnit.Engine/Services/TestExecution/TestExecutionGuard.cs +++ b/TUnit.Engine/Services/TestExecution/TestExecutionGuard.cs @@ -10,12 +10,12 @@ internal sealed class TestExecutionGuard { private readonly ConcurrentDictionary> _executingTests = new(); - public ValueTask TryStartExecutionAsync(string testId, Func executionFunc) + public ValueTask TryStartExecutionAsync(string testId, Func executionFunc) { // Fast path: check if test is already executing without allocating a TCS if (_executingTests.TryGetValue(testId, out var existingTcs)) { - return new ValueTask(WaitForExistingExecutionAsync(existingTcs)); + return new ValueTask(WaitForExistingExecutionAsync(existingTcs)); } var tcs = new TaskCompletionSource(); @@ -23,25 +23,23 @@ public ValueTask TryStartExecutionAsync(string testId, Func exe if (existingTcs != tcs) { - return new ValueTask(WaitForExistingExecutionAsync(existingTcs)); + return new ValueTask(WaitForExistingExecutionAsync(existingTcs)); } return ExecuteAndCompleteAsync(testId, tcs, executionFunc); } - private static async Task WaitForExistingExecutionAsync(TaskCompletionSource tcs) + private static async Task WaitForExistingExecutionAsync(TaskCompletionSource tcs) { await tcs.Task.ConfigureAwait(false); - return false; } - private async ValueTask ExecuteAndCompleteAsync(string testId, TaskCompletionSource tcs, Func executionFunc) + private async ValueTask ExecuteAndCompleteAsync(string testId, TaskCompletionSource tcs, Func executionFunc) { try { await executionFunc().ConfigureAwait(false); tcs.SetResult(true); - return true; } catch (Exception ex) {