Correzione: la prova da capo a fondo del server non perde più la prima sessione

«Tempo scaduto: tre file di marta.prova scaricati» era un difetto della prova: l'orologio
compresso sommava le attese dei lavori di sottofondo (circa 34 volte invece di 10, a salti) e
consumava in un attimo i limiti delle pagine vere e la prima sessione; inoltre il motore apriva
la sua sessione a «Ho finito», prima di «Controlla ora», con luca.prova per primo. Finita la
sessione, i file aspettavano la prossima: 120 secondi veri, più dei 90 della prova.

Ora le composizioni intere usano ScaledClock (attese sovrapposte = stesso tempo, 5 volte), la sola
sessione è quella chiesta con «Controlla ora», e un'attesa scaduta dice che cosa faceva Febe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 17:00:10 +01:00
1 parent 6d66cf96d3
commit 66a3873554
12 files changed
+242 -83

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
using System.Diagnostics;
using Febe.Core.Abstractions;
namespace Febe.Tests.Support;
/// <summary>
/// A clock that runs <see cref="Factor"/> times faster than the real one: <see cref="Now"/> is a function of the real
/// time alone, and <see cref="Delay"/> waits that fraction of the requested time. For whole compositions, where many
/// background loops wait at the same time: their waits overlap as they do in reality, so none of them moves the time
/// of the others. (A clock that adds every wait to <see cref="Now"/> counts overlapping waits more than once: the time
/// then jumps, and a 30-second limit on a real browser may end at once.) Measured with the monotonic timer, so a
/// correction of the system time does not move it.
/// </summary>
internal sealed class ScaledClock(double factor, TimeZoneInfo? zone = null) : IClock
{
private readonly DateTimeOffset _start = DateTimeOffset.UtcNow;
private readonly long _startStamp = Stopwatch.GetTimestamp();
public double Factor { get; } = factor >= 1 ? factor : throw new ArgumentOutOfRangeException(nameof(factor));
public TimeZoneInfo LocalZone { get; } = zone ?? TimeZoneInfo.Utc;
public DateTimeOffset Now => _start + (Stopwatch.GetElapsedTime(_startStamp) * Factor);
public async Task Delay(TimeSpan time, CancellationToken ct)
{
ct.ThrowIfCancellationRequested();
var target = Now + time;
for (var left = time; left > TimeSpan.Zero; left = target - Now)
{
// Task.Delay counts whole milliseconds and may end a moment early: never less than one, then look again.
var real = left / Factor;
await Task.Delay(real > TimeSpan.FromMilliseconds(1) ? real : TimeSpan.FromMilliseconds(1), ct).ConfigureAwait(false);
}
}
}