test: stabilize load-sensitive release contracts
This commit is contained in:
parent
c8c764a40e
commit
dfc841b779
8 changed files with 199 additions and 43 deletions
|
|
@ -193,32 +193,57 @@ public sealed class LandblockBuildFactoryTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Build_UsesTheSuppliedSharedReaderGate()
|
||||
public void Build_UsesTheSuppliedSharedReaderGate()
|
||||
{
|
||||
var dat = CreateDat(out RecordingDatProxy proxy);
|
||||
proxy.Add(LandblockId, new LandBlock { Id = LandblockId });
|
||||
object gate = new();
|
||||
var factory = Factory(dat, gate);
|
||||
using var started = new ManualResetEventSlim();
|
||||
LandblockBuild? result = null;
|
||||
Exception? workerError = null;
|
||||
var worker = new Thread(() =>
|
||||
{
|
||||
started.Set();
|
||||
try
|
||||
{
|
||||
result = factory.Build(Request(LandblockStreamJobKind.LoadFar));
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
workerError = error;
|
||||
}
|
||||
})
|
||||
{
|
||||
IsBackground = true,
|
||||
Name = "LandblockBuildFactory shared-gate contract",
|
||||
};
|
||||
|
||||
Monitor.Enter(gate);
|
||||
Task<LandblockBuild?> build;
|
||||
bool startedInTime;
|
||||
bool blockedOnGate;
|
||||
bool readWhileBlocked;
|
||||
try
|
||||
{
|
||||
build = Task.Run(() =>
|
||||
{
|
||||
started.Set();
|
||||
return factory.Build(Request(LandblockStreamJobKind.LoadFar));
|
||||
});
|
||||
Assert.True(started.Wait(TimeSpan.FromSeconds(2)));
|
||||
Assert.False(proxy.ReadObserved.Wait(TimeSpan.FromMilliseconds(100)));
|
||||
worker.Start();
|
||||
startedInTime = started.Wait(TimeSpan.FromSeconds(5));
|
||||
blockedOnGate = startedInTime && SpinWait.SpinUntil(
|
||||
() => (worker.ThreadState & ThreadState.WaitSleepJoin) != 0,
|
||||
TimeSpan.FromSeconds(5));
|
||||
readWhileBlocked = proxy.ReadObserved.IsSet;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Monitor.Exit(gate);
|
||||
}
|
||||
|
||||
Assert.NotNull(await build);
|
||||
bool joined = worker.Join(TimeSpan.FromSeconds(10));
|
||||
Assert.True(startedInTime, "the dedicated build thread did not start");
|
||||
Assert.True(blockedOnGate, "the build thread never blocked on the supplied gate");
|
||||
Assert.False(readWhileBlocked, "the DAT read bypassed the supplied gate");
|
||||
Assert.True(joined, "the build thread did not finish after the gate was released");
|
||||
Assert.Null(workerError);
|
||||
Assert.NotNull(result);
|
||||
Assert.True(proxy.ReadObserved.IsSet);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue