Collegamento e motore: correzioni regole-1, regole-2, regole-6, websec-1, websec-5, websec-6, engine-1, engine-2, sched-1
Pagine aperte da Alberto non sono segnali (regole-1); cookie perso fuori sessione = disconnessione (regole-2); pagina a riposo quando Alberto lascia il browser (regole-6); la lease di «Accedi»/«Usa il browser» finisce da sola dopo 2 minuti senza vista remota né finestra (websec-1); ping con scadenza sulla vista remota (websec-5); aperture della vista remota serializzate (websec-6); orologio virtuale senza fine anticipata (engine-1); la sincronizzazione della coda non duplica il compito in corso (engine-2); raccolte in evidenza programmate (sched-1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
19 files changed
+1122
-92
No files matched your search
@@ -81,6 +81,71 @@ public sealed class VirtualClockTests
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => clock.RunUntilAsync(Start.AddHours(1), CancellationToken.None, actor));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ATimerCancelledFromThePoolNeverEndsTheRunEarly()
|
||||
{
|
||||
// As EngineHost.OnBreakerChanged does: a pool thread cancels the actor's pending timer (here as soon as it is
|
||||
// registered, so that it often lands between the driver's look at the actors and its decision).
|
||||
for (var i = 0; i < 20_000; i++)
|
||||
{
|
||||
var clock = new VirtualClock(Start);
|
||||
using var session = new CancellationTokenSource();
|
||||
using var end = new CancellationTokenSource();
|
||||
var oneMinuteLater = false;
|
||||
var stop = 0;
|
||||
Task? canceller = null;
|
||||
async Task Actor()
|
||||
{
|
||||
canceller = Task.Run(() =>
|
||||
{
|
||||
while (clock.PendingTimers == 0 && Volatile.Read(ref stop) == 0)
|
||||
{
|
||||
Thread.SpinWait(20);
|
||||
}
|
||||
|
||||
session.Cancel();
|
||||
});
|
||||
try
|
||||
{
|
||||
await clock.Delay(TimeSpan.FromSeconds(5), session.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
|
||||
await clock.Delay(TimeSpan.FromMinutes(1), CancellationToken.None);
|
||||
oneMinuteLater = true;
|
||||
await clock.Delay(TimeSpan.FromDays(10), end.Token);
|
||||
}
|
||||
|
||||
var actor = Actor();
|
||||
bool reached;
|
||||
DateTimeOffset at;
|
||||
try
|
||||
{
|
||||
await clock.RunUntilAsync(Start.AddHours(1), CancellationToken.None, actor);
|
||||
reached = Volatile.Read(ref oneMinuteLater);
|
||||
at = clock.Now;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Lets the actor end in every case (also when the driver left it behind), so nothing keeps running.
|
||||
Volatile.Write(ref stop, 1);
|
||||
await canceller!;
|
||||
await end.CancelAsync();
|
||||
for (var spin = 0; !actor.IsCompleted && spin < 1000; spin++)
|
||||
{
|
||||
clock.AdvanceTo(clock.Now.AddDays(1));
|
||||
await Task.WhenAny(actor, Task.Delay(1));
|
||||
}
|
||||
}
|
||||
|
||||
Assert.IsTrue(reached, $"Run {i}: the driver returned while the actor was running, and skipped its timer.");
|
||||
Assert.AreEqual(Start.AddHours(1), at);
|
||||
Assert.IsTrue(actor.IsCanceled, $"Run {i}: the actor ends on its last timer, cancelled here.");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AutoAdvanceMovesTimeAtOnceAndRoundsToMilliseconds()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user