From 8566072c9a5cdcafdf4284606319bf4e0f88a996 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Fri, 23 Oct 2026 12:19:36 +0200 Subject: [PATCH] test: stretch timed budgets on the shared CI runner The owner's runner shares its CPU and disks with Gitea and the server's other containers, so the 100k-frame bulk insert took 10-19 s against 15 s from one run to the next. CHRONOS_TEST_TIME_FACTOR (default 1) stretches the timed tests' budgets; CI and release set 3, the weekly performance gates keep them. Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/ci.yml | 3 +++ .gitea/workflows/release.yml | 2 ++ docs/DECISIONS.md | 1 + .../Visuals/VisualsSmokeTests.cs | 2 +- .../Analysis/LightAnalyzerTests.cs | 2 +- .../Codecs/JpegPerformanceTests.cs | 2 +- .../Imaging/ResamplerTests.cs | 2 +- .../Metadata/RobustnessTests.cs | 2 +- .../Raw/RawPerformanceTests.cs | 4 ++-- .../Repositories/BulkInsertTests.cs | 2 +- tests/Chronos.Testing/TestTiming.cs | 23 +++++++++++++++++++ tests/Chronos.Tools.Tests/TestTimingTests.cs | 18 +++++++++++++++ 12 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 tests/Chronos.Testing/TestTiming.cs create mode 100644 tests/Chronos.Tools.Tests/TestTimingTests.cs diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 8af9d4d6..a0cf340d 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -16,6 +16,9 @@ env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "1" TOOLS: src/Chronos.Tools/bin/Release/net10.0/Chronos.Tools.dll BUILD_CPUS: "4" + # The runner shares its CPU and disks with the server's other services: timed tests get three times their budget + # (Chronos.Testing TestTiming); the performance gates of perf.yml keep theirs. + CHRONOS_TEST_TIME_FACTOR: "3" jobs: build: diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 249d2032..40b3b888 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -22,6 +22,8 @@ env: DOTNET_CLI_TELEMETRY_OPTOUT: "1" TOOLS: src/Chronos.Tools/bin/Release/net10.0/Chronos.Tools.dll BUILD_CPUS: "4" + # Timed tests get three times their budget on the shared runner (Chronos.Testing TestTiming, as in ci.yml). + CHRONOS_TEST_TIME_FACTOR: "3" TAG: ${{ github.event.inputs.tag || github.ref_name }} # Where people and programs reach Gitea (the runner itself uses github.server_url). Variable PUBLIC_URL overrides it. PUBLIC_URL: ${{ vars.PUBLIC_URL || 'https://gitea.encke-hake.ts.net' }} diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index 4baf84d0..254f5b46 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -427,3 +427,4 @@ One line per decision: date · decision · alternative · reason. | 2026-10-23 | The server image is built for linux/amd64 only and pushed to the Gitea container registry (`//chronos-server`) with the `REGISTRY_TOKEN` secret; `:latest` moves only to the highest stable version among the published releases, read back after publishing. The workflow's own token is refused by the organisation's registry (measured), so without the secret the image job fails with instructions while the release itself is already published. (R3.) | Multi-arch with QEMU; fail the whole release | Multi-arch needs QEMU's binfmt handlers installed on the owner's host, a change to the host outside the repository; the Windows programs should not wait on a registry credential. | | 2026-10-23 | The Windows-only CI (Core.Windows and App tests, screenshots and their diff, the installer test) is the `windows` job, run only when the repository variable `WINDOWS_RUNNER` names a Windows act_runner in host mode; until then those tests run on a Windows PC before a merge. The Definition of Done says so (CLAUDE.md, BRIEF Appendix A). (R3.) | Drop them; fail CI without a Windows runner | They are the only automatic proof of the installer and the screens; a job that waits for a runner that does not exist would hold every run. | | 2026-10-23 | Update check: the client reads the published stable releases and takes the highest version, because Gitea's `releases/latest` is the most recently created release (a re-published older tag or a backport would become it); a pre-release build (`0.1.0-rc.1`) is offered the final release of its own version, which it used to call "up to date" forever; a 404 is a failed check, because Gitea answers 404 for a repository the client may not see (the `BalboSoft` organisation is private today) and that used to read as "up to date". The release workflow picks `:latest` the same way. `gitea-release` checks every file's size before it publishes, and when it replaces the files of a release clients can already see it removes the old `SHA256SUMS` first and uploads the new one last. (R2, R3; independent review of this change.) | Trust `releases/latest`; leave the pre-release rule as it was | The first release is a pre-release: its testers must be told when 0.1.0 is out; a download checked against the checksums of another build would be refused. | +| 2026-10-23 | Timed tests (bulk insert, JPEG and RAW decode, resampler, light analysis, metadata robustness, scroll smoke) take their budget from `TestTiming.Budget`, stretched by `CHRONOS_TEST_TIME_FACTOR` (at least 1, default 1); ci.yml and release.yml set 3, perf.yml nothing. On the owner's runner, which shares its CPU and disks with Gitea and the server's other containers, the 100k-frame SQLite bulk insert took 10–19 s against 15 s from one run to the next. (R3.) | Raise the budgets; move the timed tests to perf.yml | The budgets stay what a developer's PC must meet and the weekly performance gates measure them unstretched; a CI run fails on a real regression, not on a busy host. | diff --git a/tests/Chronos.App.Tests/Visuals/VisualsSmokeTests.cs b/tests/Chronos.App.Tests/Visuals/VisualsSmokeTests.cs index 845223d0..1c467eec 100644 --- a/tests/Chronos.App.Tests/Visuals/VisualsSmokeTests.cs +++ b/tests/Chronos.App.Tests/Visuals/VisualsSmokeTests.cs @@ -80,7 +80,7 @@ public sealed class VisualsSmokeTests list.UpdateLayout(); } stopwatch.Stop(); - Assert.Less(stopwatch.Elapsed.TotalSeconds, 5, "300 scroll steps"); + Assert.Less(stopwatch.Elapsed.TotalSeconds, TestTiming.Budget(5), "300 scroll steps"); Assert.LessOrEqual(panel.Children.Count, rows * columns); panel.SetVerticalOffset(panel.ExtentHeight / 2); diff --git a/tests/Chronos.Core.Tests/Analysis/LightAnalyzerTests.cs b/tests/Chronos.Core.Tests/Analysis/LightAnalyzerTests.cs index 1be18bc0..eb542b91 100644 --- a/tests/Chronos.Core.Tests/Analysis/LightAnalyzerTests.cs +++ b/tests/Chronos.Core.Tests/Analysis/LightAnalyzerTests.cs @@ -184,7 +184,7 @@ public sealed class LightAnalyzerTests(TestContext context) context.Log(string.Create(CultureInfo.InvariantCulture, $"10,000 frames analysed in {watch.Elapsed.TotalMilliseconds:F1} ms")); Assert.Equal(10_000, report.DayPhases.Length); Assert.Count(1, report.ExposureSteps); - Assert.Less(watch.Elapsed.TotalSeconds, 2); + Assert.Less(watch.Elapsed.TotalSeconds, TestTiming.Budget(2)); } [Test] diff --git a/tests/Chronos.Core.Tests/Codecs/JpegPerformanceTests.cs b/tests/Chronos.Core.Tests/Codecs/JpegPerformanceTests.cs index c7e9c20a..aea298ef 100644 --- a/tests/Chronos.Core.Tests/Codecs/JpegPerformanceTests.cs +++ b/tests/Chronos.Core.Tests/Codecs/JpegPerformanceTests.cs @@ -42,7 +42,7 @@ public sealed class JpegPerformanceTests(TestContext context) $"decode all cores {parallel.TotalMilliseconds:F0} ms"); Console.WriteLine($"[perf] {context.LogText.Trim()}"); Assert.Equal(W, image!.Width); - Assert.Less(single.TotalSeconds, 3.0); + Assert.Less(single.TotalSeconds, TestTiming.Budget(3.0)); } /// Photo-like content: smooth illumination, texture and mild noise (≈ q90 file size of a real photo). diff --git a/tests/Chronos.Core.Tests/Imaging/ResamplerTests.cs b/tests/Chronos.Core.Tests/Imaging/ResamplerTests.cs index 43a07578..a5810040 100644 --- a/tests/Chronos.Core.Tests/Imaging/ResamplerTests.cs +++ b/tests/Chronos.Core.Tests/Imaging/ResamplerTests.cs @@ -151,6 +151,6 @@ public sealed class ResamplerTests(TestContext context) using var lanczos = Resampler.Resize(source, 1920, 1280); context.Log($"24 MP → 320 px box {box.TotalMilliseconds:F0} ms; → 1920 px Lanczos3 {sw.Elapsed.TotalMilliseconds:F0} ms"); Assert.Equal(320, thumb.Width); - Assert.Less(box.TotalSeconds, 2.5); + Assert.Less(box.TotalSeconds, TestTiming.Budget(2.5)); } } diff --git a/tests/Chronos.Core.Tests/Metadata/RobustnessTests.cs b/tests/Chronos.Core.Tests/Metadata/RobustnessTests.cs index f66e6338..97a43c2e 100644 --- a/tests/Chronos.Core.Tests/Metadata/RobustnessTests.cs +++ b/tests/Chronos.Core.Tests/Metadata/RobustnessTests.cs @@ -125,7 +125,7 @@ public sealed class RobustnessTests(TestContext context) } watch.Stop(); context.Log($"2000 JPEG headers in {watch.ElapsedMilliseconds} ms"); - Assert.Less(watch.Elapsed.TotalSeconds, 2.0); + Assert.Less(watch.Elapsed.TotalSeconds, TestTiming.Budget(2.0)); } [Test] diff --git a/tests/Chronos.Core.Tests/Raw/RawPerformanceTests.cs b/tests/Chronos.Core.Tests/Raw/RawPerformanceTests.cs index 77af13ae..1d6ce5b6 100644 --- a/tests/Chronos.Core.Tests/Raw/RawPerformanceTests.cs +++ b/tests/Chronos.Core.Tests/Raw/RawPerformanceTests.cs @@ -29,8 +29,8 @@ public sealed class RawPerformanceTests(TestContext context) Assert.Equal(W / 2, halfSize.Width); context.Log($"24 MP DNG: AHD full size {ahd.TotalMilliseconds:F0} ms, binned half size {half.TotalMilliseconds:F0} ms ({Environment.ProcessorCount} cores)"); Console.WriteLine($"[perf] {context.LogText.Trim()}"); - Assert.Less(ahd.TotalSeconds, 4.0); - Assert.Less(half.TotalSeconds, 1.0); + Assert.Less(ahd.TotalSeconds, TestTiming.Budget(4.0)); + Assert.Less(half.TotalSeconds, TestTiming.Budget(1.0)); } /// Best of two runs (the machine is shared; the first run also pays JIT warm-up). diff --git a/tests/Chronos.Data.Tests/Repositories/BulkInsertTests.cs b/tests/Chronos.Data.Tests/Repositories/BulkInsertTests.cs index 878fcad0..7bd4efcf 100644 --- a/tests/Chronos.Data.Tests/Repositories/BulkInsertTests.cs +++ b/tests/Chronos.Data.Tests/Repositories/BulkInsertTests.cs @@ -22,7 +22,7 @@ public abstract class BulkInsertTests(TestContext context) : RepositoryTest(cont Assert.Equal(100_000L, await db.Frames.BulkInsertAsync(frames, Ct)); watch.Stop(); Context.Log($"{Dialect}: 100k frames in {watch.Elapsed.TotalSeconds:F2} s"); - Assert.Less(watch.Elapsed.TotalSeconds, 15.0, "bulk insert time"); + Assert.Less(watch.Elapsed.TotalSeconds, TestTiming.Budget(15.0), "bulk insert time"); var refreshed = await db.Sequences.RefreshStatsAsync(sequence.Id, Ct); Assert.Equal(100_000, refreshed!.FrameCount); diff --git a/tests/Chronos.Testing/TestTiming.cs b/tests/Chronos.Testing/TestTiming.cs new file mode 100644 index 00000000..87370294 --- /dev/null +++ b/tests/Chronos.Testing/TestTiming.cs @@ -0,0 +1,23 @@ +using System.Globalization; + +namespace Chronos.Testing; + +/// +/// Time budgets of timed tests. CHRONOS_TEST_TIME_FACTOR (at least 1, default 1) stretches them on a CI runner +/// that shares its CPU and disks with other services (the Gitea runner on the owner's server, amended 2026-10-23, R3); +/// on a development PC the budgets apply as written, and the performance gates of perf.yml never set it. +/// +public static class TestTiming +{ + public const string Variable = "CHRONOS_TEST_TIME_FACTOR"; + + /// The factor from ; 1 when unset, unreadable or below 1. + public static double Factor { get; } = Parse(Environment.GetEnvironmentVariable(Variable)); + + /// stretched by . + public static double Budget(double seconds) => seconds * Factor; + + /// The factor a value of gives. + public static double Parse(string? value) => + double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var factor) && factor >= 1 && double.IsFinite(factor) ? factor : 1; +} diff --git a/tests/Chronos.Tools.Tests/TestTimingTests.cs b/tests/Chronos.Tools.Tests/TestTimingTests.cs new file mode 100644 index 00000000..b6eef18c --- /dev/null +++ b/tests/Chronos.Tools.Tests/TestTimingTests.cs @@ -0,0 +1,18 @@ +using Chronos.Testing; + +namespace Chronos.Tools.Tests; + +/// Time budgets stretch only by an explicit factor of at least 1 (BRIEF §20.1, amended 2026-10-23, R3). +public sealed class TestTimingTests +{ + [Theory] + [Case("3", 3.0)] + [Case("1.5", 1.5)] + [Case(null, 1.0)] + [Case("", 1.0)] + [Case("0.5", 1.0)] + [Case("fast", 1.0)] + [Case("Infinity", 1.0)] + public void TheFactorIsReadInvariantlyAndNeverShrinksABudget(string? value, double expected) => + Assert.Equal(expected, TestTiming.Parse(value)); +}