Prove che cadevano con il runner carico (#46)
verifica / controlli (push) Successful in 25s
verifica / prove (push) Successful in 25m9s
verifica / installatore (push) Successful in 7m37s
verifica / immagine (push) Successful in 20m21s

Le prove cadevano a ogni carico della CI, ogni volta prove diverse. Dietro alcune c'erano
difetti veri: FebeDatabase lasciava i file aperti dopo DisposeAsync (comandi SQLite non
chiusi, pool di lettura chiuso dopo lo scrittore), e il WAL spariva durante lo spostamento
della cartella Dati; la scheda dell'account senza statistiche leggeva i file di tutta la
libreria; l'arresto di FebeApp non aspettava i lavori aggiunti da un avvio in corso.
Chromium ha 120 s per avviarsi e aprire la prima scheda, e il ricollegamento smette appena
il processo cambia.

Nelle prove i limiti di tempo diventano protezioni contro un blocco: attese per condizione
con un aiuto comune, limiti per classe nella prova di scala con il tempo migliore, porta 0 e
stderr di Chromium nel browser delle prove, e la prova di «Scollega» di WebView2 controlla
che il processo esca davvero. Provato su Windows con tutti i core occupati.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-13 19:50:40 +01:00
1 parent e2e64c09e8
commit 0775a1460f
34 files changed
+875 -245

No files matched your search

@@ -22,6 +22,8 @@ namespace Febe.Tests.Collection;
[TestClass]
public sealed class DownloadQueueTests
{
public TestContext TestContext { get; set; } = null!;
[TestMethod]
public async Task A429OfTheCdnIsAThrottleSignalThatStopsTheQueueWithoutCountingAnAttempt()
{
@@ -141,7 +143,7 @@ public sealed class DownloadQueueTests
}
[TestMethod]
[Timeout(30_000, CooperativeCancellation = true)]
[Timeout(60_000, CooperativeCancellation = true)]
public async Task ManyWakeCallsDuringAPassGiveOneMorePassNotOneEach()
{
using var temp = new TempFolder("coda-sveglia");
@@ -151,19 +153,24 @@ public sealed class DownloadQueueTests
// Every pass tries the file again (no wait between attempts here): the passes are the attempts.
var fetcher = ScriptedFetcher.Status(503);
var queue = new DownloadQueue(library.Db, library.Ingest, fetcher, new FakeDataBudget(), new IdleClock(), new SeededRandom(1),
var clock = new IdleClock();
var queue = new DownloadQueue(library.Db, library.Ingest, fetcher, new FakeDataBudget(), clock, new SeededRandom(1),
new DownloadOptions { StagingFolder = temp.Combine("dati", "temporanei"), RetryDelays = [], MaxAttempts = 1000 });
for (var i = 0; i < 50; i++)
{
queue.Wake(); // e.g. one per «ricetta.*» event of a long session
}
// Every pass ends by starting an idle wait (a wake cuts it short): the second one means two passes are done.
// By condition, not by a time window two passes must fit in (#46).
using var stop = new CancellationTokenSource();
var running = queue.RunAsync(stop.Token);
await Task.Delay(TimeSpan.FromMilliseconds(500));
await clock.SecondIdle.Task.WaitAsync(TimeSpan.FromSeconds(20), TestContext.CancellationToken);
await Task.Delay(TimeSpan.FromMilliseconds(300), TestContext.CancellationToken); // negative check: no third pass
await stop.CancelAsync();
await Assert.ThrowsAsync<OperationCanceledException>(() => running);
Assert.AreEqual(2, fetcher.Calls, "The pass, then one more for all the calls: then it waits.");
Assert.AreEqual(2, clock.IdleWaits, "After the second pass the queue waits: nothing wakes it again.");
}
[TestMethod]
@@ -450,12 +457,32 @@ public sealed class DownloadQueueTests
/// <summary>A clock whose short waits (pauses between files) pass at once and whose long ones (idle) never end.</summary>
private sealed class IdleClock : IClock
{
private int _idleWaits;
public DateTimeOffset Now => Make.T0;
public TimeZoneInfo LocalZone => TestZones.Rome;
public Task Delay(TimeSpan time, CancellationToken ct) =>
time < TimeSpan.FromSeconds(10) ? Task.CompletedTask : Task.Delay(Timeout.Infinite, ct);
/// <summary>How many idle waits started.</summary>
public int IdleWaits => Volatile.Read(ref _idleWaits);
/// <summary>Completed when the second idle wait starts.</summary>
public TaskCompletionSource SecondIdle { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously);
public Task Delay(TimeSpan time, CancellationToken ct)
{
if (time < TimeSpan.FromSeconds(10))
{
return Task.CompletedTask;
}
if (Interlocked.Increment(ref _idleWaits) == 2)
{
SecondIdle.TrySetResult();
}
return Task.Delay(Timeout.Infinite, ct);
}
}
/// <summary>A content stream that runs <paramref name="midway"/> once, half way through.</summary>
@@ -45,7 +45,7 @@ public sealed class ProbeIntegrationTests
}
[TestMethod]
[Timeout(60_000, CooperativeCancellation = true)]
[Timeout(180_000, CooperativeCancellation = true)]
public async Task TheProbeRecordsResponsesAndTargetsWithoutGesturesAndItsSamplesCleanUp()
{
if (s_unavailable is not null)
@@ -65,12 +65,18 @@ public sealed class ProbeIntegrationTests
// Alberto opens a profile and points at the «Reel» tab.
var cdp = s_chromium.Cdp;
await cdp.NavigateAsync(site.Url("/profilo/marta.prova/"));
await cdp.WaitForLoadAsync(new SystemClock(), TimeSpan.FromSeconds(10));
await Task.Delay(800);
Assert.IsTrue(await cdp.WaitForLoadAsync(new SystemClock(), TimeSpan.FromSeconds(60)), "Il profilo non ha finito di caricare.");
// By condition, not after fixed pauses (#46): the data answer recorded and the tab drawn.
await TestWait.UntilAsync(
async () => probe.Stats.Responses >= 1
&& (await cdp.EvaluateAsync("[...document.querySelectorAll('a[role=tab]')].some((a) => a.textContent === 'Reel')")).ValueKind == JsonValueKind.True,
"i dati del profilo registrati e la scheda «Reel» disegnata",
ct: TestContext.CancellationToken);
var tab = await cdp.EvaluateAsync("(() => { const r = [...document.querySelectorAll('a[role=tab]')].find((a) => a.textContent === 'Reel').getBoundingClientRect(); return { x: r.left + r.width / 2, y: r.top + r.height / 2 }; })()");
var alberto = new HumanGestures(cdp, new SystemClock(), new SeededRandom(5));
await alberto.MoveToAsync(new PagePoint(tab.GetProperty("x").GetDouble(), tab.GetProperty("y").GetDouble()));
await Task.Delay(600);
await TestWait.UntilAsync(() => HoverRecorded(raw), "il passaggio sulla scheda «Reel» registrato", ct: TestContext.CancellationToken);
await probe.StopAsync();
Assert.IsTrue(probe.Stats.Responses >= 1, "The profile data was recorded.");
}
@@ -90,9 +96,7 @@ public sealed class ProbeIntegrationTests
}
var interactions = File.ReadAllLines(Path.Combine(raw, "interazioni.jsonl"));
Assert.IsTrue(
interactions.Any(l => l.Contains("\"sopra\"", StringComparison.Ordinal) && l.Contains("\"role\":\"tab\"", StringComparison.Ordinal) && l.Contains("Reel", StringComparison.Ordinal)),
"The hovered tab is described with role and accessible name: " + string.Join(" | ", interactions));
Assert.IsTrue(interactions.Any(IsReelHover), "The hovered tab is described with role and accessible name: " + string.Join(" | ", interactions));
Assert.IsTrue(File.ReadAllText(Path.Combine(raw, "navigazioni.jsonl")).Contains("/profilo/marta.prova/", StringComparison.Ordinal));
// M0 path: clean, then verify.
@@ -118,4 +122,21 @@ public sealed class ProbeIntegrationTests
public IDisposable On(string eventName, Action<JsonElement> handler) => inner.On(eventName, handler);
}
private static bool IsReelHover(string line) =>
line.Contains("\"sopra\"", StringComparison.Ordinal) && line.Contains("\"role\":\"tab\"", StringComparison.Ordinal) && line.Contains("Reel", StringComparison.Ordinal);
/// <summary>True once the probe has written the hover on «Reel» (the file may be in the middle of a write).</summary>
private static bool HoverRecorded(string raw)
{
try
{
var path = Path.Combine(raw, "interazioni.jsonl");
return File.Exists(path) && File.ReadAllLines(path).Any(IsReelHover);
}
catch (IOException)
{
return false;
}
}
}
@@ -146,7 +146,9 @@ public sealed class StopAndDownloadIntegrationTests
[Timeout(60_000, CooperativeCancellation = true)]
public async Task AnUnknownResponseShapeStopsTheRecipeWithTheKeyStructureOnly()
{
await using var h = await CollectionHarness.CreateAsync(Chromium, new Febe.Core.Collection.Recipes.RecipeOptions { DataTimeout = TimeSpan.FromSeconds(8) });
// The recipe waits for a recognized answer that never comes, then judges what it captured: the wait must leave the
// page time to load and its body to be read. 8 s of real time, on the clock compressed 10× (#46).
await using var h = await CollectionHarness.CreateAsync(Chromium, new Febe.Core.Collection.Recipes.RecipeOptions { DataTimeout = TimeSpan.FromSeconds(80) });
var marta = await h.AddAccountAsync("marta.prova");
h.Site.Control.Set(StopMode.UnknownFormat);