Skip to content

Commit 15a1741

Browse files
perf: use ConcurrentDictionary in TestRunner
1 parent 4d9d51e commit 15a1741

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

TUnit.Engine/Scheduling/TestRunner.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
using Microsoft.Testing.Platform.Extensions.Messages;
1+
using System.Collections.Concurrent;
22
using TUnit.Core;
3-
using TUnit.Core.Data;
43
using TUnit.Engine.Interfaces;
54
using TUnit.Engine.Logging;
65
using TUnit.Engine.Services.TestExecution;
@@ -36,13 +35,17 @@ internal TestRunner(
3635
_testStateManager = testStateManager;
3736
}
3837

39-
private readonly ThreadSafeDictionary<string, TaskCompletionSource<bool>> _executingTests = new();
38+
private readonly ConcurrentDictionary<string, TaskCompletionSource<bool>> _executingTests = new();
4039
private Exception? _firstFailFastException;
4140

4241
public ValueTask ExecuteTestAsync(AbstractExecutableTest test, CancellationToken cancellationToken)
4342
{
43+
if (_executingTests.TryGetValue(test.TestId, out var existingTcs))
44+
{
45+
return new ValueTask(existingTcs.Task);
46+
}
4447
var tcs = new TaskCompletionSource<bool>();
45-
var existingTcs = _executingTests.GetOrAdd(test.TestId, _ => tcs);
48+
existingTcs = _executingTests.GetOrAdd(test.TestId, tcs);
4649

4750
if (existingTcs != tcs)
4851
{

0 commit comments

Comments
 (0)