fix: full verification against the brief — 137 confirmed findings fixed over six passes #4
@@ -162,7 +162,7 @@ public sealed class ProjectFilesTests(TestContext context)
|
|||||||
Assert.Null(SingleInstance.TryAcquire(data));
|
Assert.Null(SingleInstance.TryAcquire(data));
|
||||||
|
|
||||||
// The next launch waits (the mutex belongs to a thread, so it waits on its own) and gets its turn once the first exits.
|
// The next launch waits (the mutex belongs to a thread, so it waits on its own) and gets its turn once the first exits.
|
||||||
var next = Task.Run(() =>
|
var next = OnOwnThread(() =>
|
||||||
{
|
{
|
||||||
using var instance = SingleInstance.WaitForTurn(data, TimeSpan.FromSeconds(20));
|
using var instance = SingleInstance.WaitForTurn(data, TimeSpan.FromSeconds(20));
|
||||||
return instance is not null;
|
return instance is not null;
|
||||||
@@ -175,7 +175,7 @@ public sealed class ProjectFilesTests(TestContext context)
|
|||||||
var holder = Assert.NotNull(SingleInstance.TryAcquire(data));
|
var holder = Assert.NotNull(SingleInstance.TryAcquire(data));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Assert.False(Task.Run(() => SingleInstance.WaitForTurn(data, TimeSpan.FromMilliseconds(200)) is { } got && Dispose(got)).Result);
|
Assert.False(OnOwnThread(() => SingleInstance.WaitForTurn(data, TimeSpan.FromMilliseconds(200)) is { } got && Dispose(got)).Result);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -187,6 +187,26 @@ public sealed class ProjectFilesTests(TestContext context)
|
|||||||
instance.Dispose();
|
instance.Dispose();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A thread of its own, never this one: a mutex this thread owns would let it in at once, and a task waited on
|
||||||
|
// before it started may run inline on the waiting thread.
|
||||||
|
static Task<bool> OnOwnThread(Func<bool> launch)
|
||||||
|
{
|
||||||
|
var done = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
new Thread(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
done.SetResult(launch());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
done.SetException(ex);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
{ IsBackground = true }.Start();
|
||||||
|
return done.Task;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Dialogs that pick one folder and cancel everything else.</summary>
|
/// <summary>Dialogs that pick one folder and cancel everything else.</summary>
|
||||||
|
|||||||
Reference in new issue
Block a user