diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 1e7aa75..d5b286e 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -12,6 +12,8 @@ jobs: runs-on: ubuntu-latest container: image: mcr.microsoft.com/dotnet/sdk:10.0 + # The databases of the tests live in memory: the disk of the runner stops for seconds under load (ADR 0019). + options: --tmpfs /test-tmp:size=4g strategy: fail-fast: false matrix: @@ -50,7 +52,9 @@ jobs: git -c http.extraHeader="Authorization: token ${{ github.token }}" fetch -q --depth 1 origin "${{ github.sha }}" git checkout -q FETCH_HEAD - name: Check - run: sh ./tasks.sh check + run: | + df -h /test-tmp + TMPDIR=/test-tmp sh ./tasks.sh check # The log of the PostgreSQL service, read through the Docker socket the runner mounts in the job (issue #98). - name: PostgreSQL log if: always() && matrix.db == 'postgres' diff --git a/docs/adr/0019-prove-sqlite-in-memoria.md b/docs/adr/0019-prove-sqlite-in-memoria.md new file mode 100644 index 0000000..f6007d9 --- /dev/null +++ b/docs/adr/0019-prove-sqlite-in-memoria.md @@ -0,0 +1,26 @@ +# 0019 — Nella CI i database SQLite delle prove stanno in memoria + +Data: 2026-12-01 · Stato: accettata · Continua l'ADR 0015 (CI, SPEC 15.5), senza componenti esterni nuovi + +## Contesto + +Il 1° dicembre 2026 la CI di `main` (run 557, lavoro `test (sqlite)`) è fallita in `HealthChecksDatabaseAndScheduler`: `/health` ha risposto 503. Il registro mostra che per oltre 6 secondi nessun test è avanzato, e il ping al database ha superato il suo limite di 5 secondi. Lo stesso codice era passato sul branch e nel lavoro PostgreSQL. + +È la causa già vista nell'ADR 0015: il disco dell'esecutore su Unraid si ferma per secondi sotto carico. Lì il rimedio riguardava solo PostgreSQL. I database SQLite dei test sincronizzano ogni scrittura (`synchronous=FULL`, come dal vivo), e la Fase 8 ne ha aggiunti molti. + +## Decisione + +1. **Cartella temporanea in memoria.** Il contenitore del lavoro `test` monta un `tmpfs` da 4 GB al massimo in `/test-tmp`, e le prove la usano come cartella temporanea (`TMPDIR`). Il codice di Anubis e le impostazioni di SQLite restano quelli veri. +2. **Il test di `/health` aspetta.** Un computer fermo da più di 5 secondi *deve* risultare non disponibile: il test guarda la risposta a cui si arriva entro 30 secondi. Uno scheduler o un database davvero fermi lo fanno fallire ancora, e il messaggio dice quale. + +## Alternative scartate + +- `synchronous=OFF` nei test: cambierebbe il codice che si prova. +- Rilanciare il lavoro: nasconde la causa. +- Meno test in parallelo: la CI durerebbe di più e il disco si fermerebbe lo stesso. + +## Conseguenze + +- I test SQLite della CI non provano la durata dei dati dopo un'interruzione di corrente: non lo facevano nemmeno prima. +- In locale non cambia niente. +- Il passo `Check` stampa lo spazio della cartella: se il montaggio sparisse si vedrebbe lì. diff --git a/tests/Anubis.Tests/ServerTests.cs b/tests/Anubis.Tests/ServerTests.cs index 630e7c1..35c15f1 100644 --- a/tests/Anubis.Tests/ServerTests.cs +++ b/tests/Anubis.Tests/ServerTests.cs @@ -439,8 +439,17 @@ public sealed class ServerTests var (env, postgres) = await ServerHarness.DockerOnEngineAsync(); await using var engine = postgres; await using var server = await ServerHarness.StartAsync("docker", env); - var health = await server.Http.GetFromJsonAsync(new Uri("/health", UriKind.Relative)); - Assert.AreEqual("ok", health!.Status); + + // A computer stopped for more than the five seconds of the check is told unhealthy, as it should: here the + // answer that counts is the one it settles on, within thirty seconds. + HealthResponse? health = null; + for (var watch = System.Diagnostics.Stopwatch.StartNew(); health?.Status != "ok" && watch.Elapsed < TimeSpan.FromSeconds(30); await Task.Delay(100)) + { + using var response = await server.GetAsync("/health"); + health = await response.Content.ReadFromJsonAsync(); + } + + Assert.AreEqual("ok", health!.Status, string.Join(", ", health.Checks!.Select(c => c.Key + " " + c.Value))); Assert.AreEqual("ok", health.Checks!["database"]); Assert.AreEqual("ok", health.Checks["scheduler"]); }