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:
1 parent
6d66cf96d3
commit
66a3873554
12 files changed
+242
-83
No files matched your search
@@ -0,0 +1,59 @@
|
||||
using System.Diagnostics;
|
||||
using Febe.Core.Collection.Readers;
|
||||
using Febe.Core.Collection.Recipes;
|
||||
using Febe.Tests.Support;
|
||||
|
||||
namespace Febe.Tests.Server;
|
||||
|
||||
/// <summary>
|
||||
/// The clock of the end-to-end tests (<see cref="ScaledClock"/>): waits that overlap must not add up. With a clock that
|
||||
/// adds them up, the background loops of the server used up the time limits of the real browser and the few minutes of
|
||||
/// the first session in a moment, and the files of the end-to-end test came only after the next one («Tempo scaduto: tre
|
||||
/// file di marta.prova scaricati»). The bounds follow the real time measured around, so a loaded runner does not fail them.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public sealed class ScaledClockTests
|
||||
{
|
||||
public TestContext TestContext { get; set; } = null!;
|
||||
|
||||
[TestMethod]
|
||||
public async Task OverlappingWaitsPassTheSameTime()
|
||||
{
|
||||
const double factor = 100;
|
||||
var clock = new ScaledClock(factor);
|
||||
var real = Stopwatch.StartNew();
|
||||
var before = clock.Now;
|
||||
await Task.WhenAll(Enumerable.Range(0, 10).Select(_ => clock.Delay(TimeSpan.FromSeconds(30), TestContext.CancellationToken)));
|
||||
var passed = clock.Now - before;
|
||||
|
||||
Assert.IsGreaterThanOrEqualTo(TimeSpan.FromSeconds(30), passed, "every wait lasted its whole time");
|
||||
Assert.IsLessThanOrEqualTo(real.Elapsed * factor, passed, "ten waits together pass the time of one, not of ten");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AWaitForThePageIsNotCutShortByTheLongWaitOfAnotherLoop()
|
||||
{
|
||||
// The wait of the recipes for the data of a page, as they do it, while another loop's long wait ends in the middle.
|
||||
const double factor = 20;
|
||||
var clock = new ScaledClock(factor);
|
||||
var capture = new CaptureCollector(new ShapeReader(ReaderVocabulary.LoadTestSite()), clock);
|
||||
var other = clock.Delay(TimeSpan.FromSeconds(60), TestContext.CancellationToken);
|
||||
await clock.Delay(TimeSpan.FromSeconds(50), TestContext.CancellationToken);
|
||||
|
||||
var real = Stopwatch.StartNew();
|
||||
await capture.WaitAsync(capture.Mark(), _ => false, TimeSpan.FromSeconds(20), TimeSpan.FromMilliseconds(100), TestContext.CancellationToken);
|
||||
Assert.IsGreaterThanOrEqualTo(TimeSpan.FromSeconds(20 / factor) - TimeSpan.FromMilliseconds(50), real.Elapsed, "the page had its whole time");
|
||||
await other;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AWaitEndsWhenItIsCancelled()
|
||||
{
|
||||
var clock = new ScaledClock(10);
|
||||
using var cancel = new CancellationTokenSource();
|
||||
var wait = clock.Delay(TimeSpan.FromHours(1), cancel.Token);
|
||||
await cancel.CancelAsync();
|
||||
await Assert.ThrowsAsync<OperationCanceledException>(() => wait);
|
||||
await Assert.ThrowsAsync<OperationCanceledException>(() => clock.Delay(TimeSpan.Zero, cancel.Token));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user