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

+78 -14
View File
@@ -37,6 +37,8 @@ public sealed class FebeApp : IAsyncDisposable
private readonly FebeAppOptions _options;
private readonly IFebePlatform _platform;
private readonly CancellationTokenSource _lifetime = new();
// The start adds to these lists from its background tasks while a stop may already be running (#46): one lock.
private readonly Lock _gate = new();
private readonly List<Task> _background = [];
private readonly List<IDisposable> _disposables = [];
private readonly List<Action> _unsubscribe = [];
@@ -261,14 +263,14 @@ public sealed class FebeApp : IAsyncDisposable
services.Diagnostics = diagnostics;
EventHandler<Permit> permitDenied = (_, permit) => diagnostics.PermitDenied(null, permit.Kind, permit.Reason);
services.Governor.Denied += permitDenied;
_unsubscribe.Add(() => services.Governor.Denied -= permitDenied);
OnStop(() => services.Governor.Denied -= permitDenied);
var runner = new DeferredRecipeRunner();
var engine = new EngineHost(services, runner);
Engine = engine;
connection.AttachEngine(engine);
EventHandler<bool> drivingChanged = (_, _) => engine.NotifyUserDrivingChanged();
browser.UserDriving.Changed += drivingChanged;
_unsubscribe.Add(() => browser.UserDriving.Changed -= drivingChanged);
OnStop(() => browser.UserDriving.Changed -= drivingChanged);
_telegram = new TelegramClient(hooks.TelegramHandler);
var telegramChannel = new TelegramAlertChannel(_telegram);
@@ -320,10 +322,43 @@ public sealed class FebeApp : IAsyncDisposable
// Housekeeping in the background: temporary files of an interrupted run, the daily copy of the database.
var lifetime = _lifetime.Token;
_background.Add(Task.Run(() => CleanTemporaryFilesAsync(staging, layout, lifetime), CancellationToken.None));
_background.Add(Task.Run(() => BackupLoopAsync(new DailyBackup(Database, Clock, data.Backups), lifetime), CancellationToken.None));
_background.Add(Task.Run(() => BringUpBrowserAsync(ingest, staging, services, engine, runner, lifetime), CancellationToken.None));
_background.Add(Task.Run(() => Alerts.WatchDiskSpaceAsync(lifetime), CancellationToken.None));
InBackground(() => CleanTemporaryFilesAsync(staging, layout, lifetime));
InBackground(() => BackupLoopAsync(new DailyBackup(Database, Clock, data.Backups), lifetime));
InBackground(() => BringUpBrowserAsync(ingest, staging, services, engine, runner, lifetime));
InBackground(() => Alerts.WatchDiskSpaceAsync(lifetime));
}
/// <summary>Runs <paramref name="work"/> in the background; the stop waits for it.</summary>
private void InBackground(Func<Task> work)
{
lock (_gate)
{
_background.Add(Task.Run(work, CancellationToken.None));
}
}
/// <summary>Keeps <paramref name="disposable"/> for the stop; disposes it at once when the stop already took its list.</summary>
private void DisposeOnStop(IDisposable disposable)
{
lock (_gate)
{
if (Volatile.Read(ref _disposed) == 0)
{
_disposables.Add(disposable);
return;
}
}
disposable.Dispose();
}
/// <summary>Keeps <paramref name="unsubscribe"/> for the stop.</summary>
private void OnStop(Action unsubscribe)
{
lock (_gate)
{
_unsubscribe.Add(unsubscribe);
}
}
private async Task StartWebAsync(FebeAppHooks hooks, Action<IServiceCollection> register)
@@ -392,8 +427,8 @@ public sealed class FebeApp : IAsyncDisposable
runner.Target = Pipeline.Runner;
await CheckCollectionConfigurationAsync(Pipeline, engine, ct).ConfigureAwait(false);
var changes = Web.Services.GetRequiredService<LibraryChanges>();
_disposables.Add(changes.Attach(Pipeline.Downloads, Clock));
_background.Add(Task.Run(() => DownloadLoopAsync(Pipeline.Downloads, ct), CancellationToken.None));
DisposeOnStop(changes.Attach(Pipeline.Downloads, Clock));
InBackground(() => DownloadLoopAsync(Pipeline.Downloads, ct));
// Every finished recipe may have queued files: the queue looks at once instead of at its next idle poll.
var downloads = Pipeline.Downloads;
@@ -406,7 +441,7 @@ public sealed class FebeApp : IAsyncDisposable
}
services.Events.Notified += WakeDownloads;
_unsubscribe.Add(() => services.Events.Notified -= WakeDownloads);
OnStop(() => services.Events.Notified -= WakeDownloads);
await Connection!.RefreshAsync(ct).ConfigureAwait(false);
if (o.TestSiteAutoLogin && Connection.IsConnected != true)
@@ -414,7 +449,7 @@ public sealed class FebeApp : IAsyncDisposable
await TestSiteLoginAsync(ct).ConfigureAwait(false);
}
_background.Add(Task.Run(() => Connection.RunAsync(ct), CancellationToken.None));
InBackground(() => Connection.RunAsync(ct));
await engine.StartAsync(ct).ConfigureAwait(false);
Log.Info("motore", Connection.IsConnected == true
? "Motore avviato: il browser è collegato."
@@ -634,17 +669,46 @@ public sealed class FebeApp : IAsyncDisposable
}
await _lifetime.CancelAsync().ConfigureAwait(false);
foreach (var task in _background.ToArray())
// A start still in progress adds tasks while the first ones are awaited: look again until nothing new appears,
// so nothing still reads the database once it is closed (#46).
var awaited = 0;
while (true)
{
await Quietly(() => task).ConfigureAwait(false);
Task[] pending;
lock (_gate)
{
pending = _background.Skip(awaited).ToArray();
}
if (pending.Length == 0)
{
break;
}
foreach (var task in pending)
{
await Quietly(() => task).ConfigureAwait(false);
}
awaited += pending.Length;
}
foreach (var disposable in _disposables)
IDisposable[] disposables;
Action[] unsubscribes;
lock (_gate)
{
disposables = [.. _disposables];
unsubscribes = [.. _unsubscribe];
_disposables.Clear();
}
foreach (var disposable in disposables)
{
disposable.Dispose();
}
foreach (var unsubscribe in _unsubscribe)
foreach (var unsubscribe in unsubscribes)
{
unsubscribe();
}