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
15 changes: 9 additions & 6 deletions TUnit.Core/Executors/DedicatedThreadExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ protected sealed override async ValueTask ExecuteAsync(Func<ValueTask> action)

var tcs = new TaskCompletionSource<object?>();

var thread = new Thread(() =>
var thread = new Thread(static state =>
{
var (threadExecutor, action, tcs) = (ValueTuple<DedicatedThreadExecutor, Func<ValueTask>, TaskCompletionSource<object?>>)state!;
Exception? capturedException = null;

try
{
Initialize();
threadExecutor.Initialize();

try
{
ExecuteAsyncActionWithMessagePump(action, tcs);
threadExecutor.ExecuteAsyncActionWithMessagePump(action, tcs);
}
catch (Exception e)
{
Expand All @@ -41,7 +42,7 @@ protected sealed override async ValueTask ExecuteAsync(Func<ValueTask> action)
}
finally
{
CleanUp();
threadExecutor.CleanUp();

if (capturedException != null && !tcs.Task.IsCompleted)
{
Expand All @@ -50,8 +51,10 @@ protected sealed override async ValueTask ExecuteAsync(Func<ValueTask> action)
}
});

var state = (this, action, tcs);

ConfigureThread(thread);
thread.Start();
thread.Start(state);

await tcs.Task;
}
Expand Down Expand Up @@ -409,7 +412,7 @@ public override SynchronizationContext CreateCopy()
}
}

public ValueTask OnTestRegistered(TestRegisteredContext context)
public ValueTask OnTestRegistered(TestRegisteredContext context)
{
context.SetParallelLimiter(new ProcessorCountParallelLimit());
return default(ValueTask);
Expand Down
Loading