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>
143 lines
7.4 KiB
C#
143 lines
7.4 KiB
C#
using Febe.Core.Abstractions;
|
|
using Febe.Core.Domain;
|
|
using Febe.Core.Engine;
|
|
using Febe.Tests.Engine.Support;
|
|
|
|
namespace Febe.Tests.Engine;
|
|
|
|
[TestClass]
|
|
public sealed class EngineMonitorTests
|
|
{
|
|
[TestMethod]
|
|
public async Task AtNightTheMonitorSaysWhenWorkResumes()
|
|
{
|
|
var night = EngineTestBed.Local(2026, 10, 14, 2, 0);
|
|
await using var bed = await EngineTestBed.CreateAsync(night);
|
|
await bed.AddAccountAsync("marta.demo", followed: true);
|
|
var host = bed.Start(new ScriptedRunner(bed.Governor, bed.Clock));
|
|
await bed.RunForAsync(TimeSpan.FromMinutes(15));
|
|
|
|
var snapshot = await host.Monitor.GetSnapshotAsync();
|
|
Assert.AreEqual(EngineMode.OutsideWindow, snapshot.Mode);
|
|
Assert.AreEqual("Fuori fascia", snapshot.Headline);
|
|
StringAssert.Contains(snapshot.SidebarLine, "Riprende verso le ");
|
|
var window = await bed.Services.Planner.GetWindowAsync(new DateOnly(2026, 10, 14));
|
|
Assert.AreEqual(window!.Start, snapshot.ResumesAround);
|
|
Assert.IsNull(snapshot.Banner);
|
|
Assert.IsTrue(snapshot.Today.Spans.Any(s => s.Kind == StripSpanKind.OutsideWindow && s.Start == snapshot.Today.Start));
|
|
Assert.IsTrue(snapshot.Today.Spans.Any(s => s.Kind == StripSpanKind.PlannedSession && s.Indicative));
|
|
Assert.IsTrue(snapshot.Queue.All(q => q.When.StartsWith("verso le", StringComparison.Ordinal)));
|
|
Assert.AreEqual(4, snapshot.MainBudgets.Count);
|
|
CollectionAssert.AreEqual(
|
|
new[] { ActionKind.ProfileOpen, ActionKind.StoryView, ActionKind.BackfillPage, ActionKind.DataDownload },
|
|
snapshot.MainBudgets.Select(b => b.Kind).ToArray());
|
|
Assert.AreEqual(Enum.GetValues<ActionKind>().Length, snapshot.AllBudgets.Count);
|
|
Assert.AreEqual("Profili aperti", snapshot.ProfilesOpenedToday.Label);
|
|
Assert.AreEqual("di 100", snapshot.ProfilesOpenedToday.LimitText);
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task DuringTheDayTheStripShowsSessionsRestsAndTheSummary()
|
|
{
|
|
await using var bed = await EngineTestBed.CreateAsync(EngineTestBed.Local(2026, 10, 14, 6, 0));
|
|
await bed.AddAccountAsync("marta.demo", followed: true);
|
|
await bed.AddAccountAsync("luca.demo", followed: false, Frequency.High);
|
|
var host = bed.Start(new ScriptedRunner(bed.Governor, bed.Clock));
|
|
await bed.RunUntilAsync(EngineTestBed.Local(2026, 10, 14, 15, 0));
|
|
|
|
var snapshot = await host.Monitor.GetSnapshotAsync();
|
|
Assert.IsTrue(snapshot.Mode is EngineMode.Resting or EngineMode.InSession);
|
|
Assert.IsTrue(snapshot.Today.Spans.Count(s => s.Kind is StripSpanKind.Session or StripSpanKind.CurrentSession) >= 5);
|
|
Assert.IsTrue(snapshot.Today.Spans.Any(s => s.Kind == StripSpanKind.Rest));
|
|
StringAssert.Contains(snapshot.Today.Summary, "sessioni");
|
|
StringAssert.Contains(snapshot.Today.Summary, "nessun rallentamento");
|
|
Assert.IsNotEmpty(snapshot.RecentActions);
|
|
Assert.IsTrue(snapshot.RecentActions.Any(a => a.Title == "Giro dei profili che segui" || a.Title.StartsWith('@')));
|
|
if (snapshot.Mode == EngineMode.Resting)
|
|
{
|
|
Assert.AreEqual("In ascolto", snapshot.Headline);
|
|
StringAssert.StartsWith(snapshot.Details[0], "Riprende verso le ");
|
|
}
|
|
|
|
var profiles = snapshot.ProfilesOpenedToday;
|
|
Assert.IsTrue(profiles.UsedToday > 0);
|
|
StringAssert.StartsWith(profiles.Note, "In questa ora ");
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task AThrottleShowsAnAmberStripAndSuspendsTheQueue()
|
|
{
|
|
await using var bed = await EngineTestBed.CreateAsync();
|
|
await bed.AddAccountAsync("marta.demo", followed: true);
|
|
var host = bed.Start(new ScriptedRunner(bed.Governor, bed.Clock));
|
|
await bed.RunForAsync(TimeSpan.FromMinutes(1));
|
|
await bed.Breaker.ReportAsync(new Signal(SignalLevel.Throttle, "http-429", null, bed.Clock.Now));
|
|
|
|
var snapshot = await host.Monitor.GetSnapshotAsync();
|
|
Assert.AreEqual(EngineMode.Throttled, snapshot.Mode);
|
|
Assert.AreEqual(BannerLevel.Warning, snapshot.Banner!.Level);
|
|
StringAssert.Contains(snapshot.Banner.Message, "tetti dimezzati");
|
|
Assert.IsTrue(snapshot.Queue.All(q => q.Suspended && q.When == "Sospeso"));
|
|
Assert.IsTrue(snapshot.Today.Spans.Any(s => s.Kind == StripSpanKind.Throttle));
|
|
StringAssert.StartsWith(snapshot.ProfilesOpenedToday.Note, "Fermo dalle ");
|
|
StringAssert.Contains(snapshot.ReductionNote!, "Tetti dimezzati");
|
|
|
|
// Future engine times are always «verso le» (spec §10.4): the strip agrees with the status box.
|
|
var resumes = ItalianText.Around(bed.Breaker.State.Until!.Value, bed.Clock.Now, bed.Clock.LocalZone);
|
|
StringAssert.Contains(snapshot.Banner.Message, "riparto da solo " + resumes);
|
|
StringAssert.Contains(snapshot.SidebarLine, resumes);
|
|
StringAssert.Contains(snapshot.ReductionNote!, "verso l");
|
|
foreach (var text in new[] { snapshot.Banner.Message, snapshot.ReductionNote! })
|
|
{
|
|
Assert.DoesNotContain(" alle ", text);
|
|
Assert.DoesNotContain(" all'", text);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task TheEventStreamDeliversTimelineLines()
|
|
{
|
|
await using var bed = await EngineTestBed.CreateAsync();
|
|
var host = bed.Start(new ScriptedRunner(bed.Governor, bed.Clock));
|
|
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
|
|
var received = new List<EngineNotification>();
|
|
|
|
// Subscribed on this thread before the pause: the first MoveNextAsync runs up to its wait and registers the
|
|
// subscriber, so no pool thread has to start in time for the event (#46).
|
|
await using var stream = host.Monitor.SubscribeAsync(cts.Token).GetAsyncEnumerator(cts.Token);
|
|
var next = stream.MoveNextAsync();
|
|
await host.PauseAsync();
|
|
while (await next)
|
|
{
|
|
var notification = stream.Current;
|
|
received.Add(notification);
|
|
if (notification.Kind == EngineNotificationKind.Event && notification.Event!.Code == EngineEventCodes.Paused)
|
|
{
|
|
break;
|
|
}
|
|
|
|
next = stream.MoveNextAsync();
|
|
}
|
|
|
|
Assert.IsTrue(received.Any(n => n.Event?.Code == EngineEventCodes.Paused));
|
|
StringAssert.Contains(received.Last().Event!.Message, "Riprendi");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ItalianTextUsesDotsCommasAndVersoLe()
|
|
{
|
|
Assert.AreEqual("7.682", ItalianText.Number(7682));
|
|
Assert.AreEqual("1.234.567", ItalianText.Number(1234567));
|
|
Assert.AreEqual("1,3 GB", ItalianText.Bytes((long)(1.3 * 1024 * 1024 * 1024)));
|
|
Assert.AreEqual("0,5", ItalianText.Decimal(0.5));
|
|
var zone = EngineTestBed.Zone;
|
|
var now = EngineTestBed.Local(2026, 10, 14, 12, 0);
|
|
Assert.AreEqual("verso le 15:30", ItalianText.Around(EngineTestBed.Local(2026, 10, 14, 15, 30), now, zone));
|
|
Assert.AreEqual("domani verso le 7:42", ItalianText.Around(EngineTestBed.Local(2026, 10, 15, 7, 42), now, zone));
|
|
Assert.AreEqual("verso l'1:05", ItalianText.Around(EngineTestBed.Local(2026, 10, 14, 13, 5).AddHours(12), now.AddHours(12), zone));
|
|
Assert.AreEqual("1 ora e 20 minuti", ItalianText.Duration(TimeSpan.FromMinutes(80)));
|
|
Assert.AreEqual("ogni 75 minuti", ItalianText.Every(TimeSpan.FromMinutes(75)));
|
|
Assert.AreEqual("ogni 3 ore", ItalianText.Every(TimeSpan.FromHours(3)));
|
|
}
|
|
}
|