Files
Alby96andClaude Opus 5.5 f2b58522b9
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout and the system SQLite. The release cross-compiles the Windows
  programs, checks their icon, version and DPI manifest, packs installers
  and zips, publishes the Gitea release and pushes the server image
  (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows
  runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow; the
  throw-away server runs without durability) and pe-check.
- Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR,
  3 on the shared runner; the weekly performance gates keep theirs).

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-23 12:45:18 +02:00

292 lines
10 KiB
C#

using System.Collections.Concurrent;
using Chronos.App.Editor;
using Chronos.Core.Project;
using Chronos.Testing;
namespace Chronos.App.Tests.Editor;
/// <summary>Debouncing and cancellation of preview work, and the coalescing project writer.</summary>
public sealed class SchedulingTests
{
[Test]
public async Task OnlyTheLastOfRapidRequestsRuns()
{
using var runner = new LatestRunner(TimeSpan.FromMilliseconds(80));
var ran = new ConcurrentQueue<int>();
var tasks = Enumerable.Range(0, 10).Select(i => runner.Schedule(_ =>
{
ran.Enqueue(i);
return Task.CompletedTask;
})).ToList();
await Task.WhenAll(tasks);
Assert.SequenceEqual([9], ran);
}
[Test]
public async Task ANewRequestCancelsTheRunningOne()
{
using var runner = new LatestRunner(TimeSpan.Zero);
var started = new TaskCompletionSource();
var cancelled = false;
var first = runner.Schedule(async token =>
{
started.SetResult();
try
{
await Task.Delay(Timeout.Infinite, token);
}
catch (OperationCanceledException)
{
cancelled = true;
throw;
}
});
await started.Task;
var second = runner.Schedule(_ => Task.CompletedTask);
await Task.WhenAll(first, second);
Assert.True(cancelled, "the superseded run saw its token cancelled");
Assert.True(first.IsCompletedSuccessfully, "a superseded run ends quietly");
}
/// <summary>Synchronous work that throws when superseded (the export estimates) ends quietly as well (R4, owner review 1).</summary>
[Test]
public async Task ASupersededSynchronousRunEndsQuietly()
{
using var runner = new LatestRunner(TimeSpan.Zero);
var started = new ManualResetEventSlim();
var first = runner.Schedule(token =>
{
started.Set();
token.WaitHandle.WaitOne(TimeSpan.FromSeconds(10));
token.ThrowIfCancellationRequested();
return Task.CompletedTask;
});
Assert.True(started.Wait(TimeSpan.FromSeconds(10)));
var second = runner.Schedule(_ => Task.CompletedTask);
await Task.WhenAll(first, second);
Assert.True(first.IsCompletedSuccessfully, "a superseded run ends quietly");
}
[Test]
public async Task ImmediateRequestsSkipTheDelay()
{
using var runner = new LatestRunner(TimeSpan.FromSeconds(30));
var ran = false;
await runner.Schedule(_ =>
{
ran = true;
return Task.CompletedTask;
}, immediate: true).WaitAsync(TimeSpan.FromSeconds(10));
Assert.True(ran);
}
[Test]
public async Task FailuresSurfaceFromTheRun()
{
using var runner = new LatestRunner(TimeSpan.Zero);
await Assert.ThrowsAsync<InvalidOperationException>(() => runner.Schedule(_ => throw new InvalidOperationException("broken")));
}
[Test]
public async Task CancelStopsThePendingRequest()
{
using var runner = new LatestRunner(TimeSpan.FromMilliseconds(200));
var ran = false;
var run = runner.Schedule(_ =>
{
ran = true;
return Task.CompletedTask;
});
runner.Cancel();
await run;
Assert.False(ran);
}
[Test]
public async Task TheSaverWritesTheNewestProjectOnce()
{
var saved = new List<int?>();
var saver = new ProjectSaver(p =>
{
saved.Add(p.HeroFrame);
return Task.CompletedTask;
}, TimeSpan.FromMilliseconds(50));
for (var i = 0; i < 5; i++) saver.Schedule(new ProjectSettings { HeroFrame = i });
await saver.FlushAsync();
Assert.SequenceEqual([(int?)4], saved);
Assert.False(saver.HasPendingChanges);
}
[Test]
public async Task FlushSkipsTheDelay()
{
var saved = 0;
var saver = new ProjectSaver(_ =>
{
saved++;
return Task.CompletedTask;
}, TimeSpan.FromMinutes(5));
saver.Schedule(new ProjectSettings());
await saver.FlushAsync().WaitAsync(TimeSpan.FromSeconds(10));
Assert.Equal(1, saved);
}
[Test]
public async Task AFailedWriteIsRetriedUntilStored()
{
var attempts = 0;
var stored = new List<int?>();
var failures = new List<int>();
var saver = new ProjectSaver(p =>
{
if (++attempts <= 2) throw new System.IO.IOException("offline");
stored.Add(p.HeroFrame);
return Task.CompletedTask;
}, TimeSpan.Zero);
saver.Failed += (_, count) => failures.Add(count);
// Without a delay the first write happens at once and fails; the flush retries at once and fails again.
saver.Schedule(new ProjectSettings { HeroFrame = 7 });
Assert.False(await saver.FlushAsync());
Assert.True(saver.HasPendingChanges, "kept pending after a failure");
Assert.NotNull(saver.LastError);
Assert.True(await saver.FlushAsync().WaitAsync(TimeSpan.FromSeconds(10)), "a flush skips the retry delay");
Assert.SequenceEqual([(int?)7], stored);
Assert.SequenceEqual([1, 2], failures, "failures in a row are counted");
Assert.False(saver.HasPendingChanges);
Assert.Null(saver.LastError);
}
[Test]
public async Task ARetryWritesTheNewestChange()
{
var fail = true;
var stored = new List<int?>();
var saver = new ProjectSaver(p =>
{
if (fail) throw new System.IO.IOException("offline");
stored.Add(p.HeroFrame);
return Task.CompletedTask;
}, TimeSpan.Zero);
saver.Schedule(new ProjectSettings { HeroFrame = 1 });
Assert.False(await saver.FlushAsync());
saver.Schedule(new ProjectSettings { HeroFrame = 2 });
fail = false;
Assert.True(await saver.FlushAsync());
Assert.SequenceEqual([(int?)2], stored, "the newer project contains the failed one");
}
[Test]
public async Task StopDropsThePendingChange()
{
var saved = 0;
var saver = new ProjectSaver(_ =>
{
saved++;
throw new System.IO.IOException("offline");
}, TimeSpan.Zero);
saver.Schedule(new ProjectSettings { HeroFrame = 1 });
Assert.False(await saver.FlushAsync());
var attempts = saved;
saver.Stop();
Assert.True(await saver.FlushAsync().WaitAsync(TimeSpan.FromSeconds(10)), "nothing pending after a stop");
saver.Schedule(new ProjectSettings { HeroFrame = 2 });
Assert.False(saver.HasPendingChanges, "a stopped saver takes no new change");
Assert.Equal(attempts, saved);
}
[Test]
public async Task AHeldChangeIsNotRetriedUntilReleased()
{
var fail = true;
var attempts = 0;
var stored = new List<int?>();
var saver = new ProjectSaver(p =>
{
attempts++;
if (fail) throw new System.IO.IOException("offline");
stored.Add(p.HeroFrame);
return Task.CompletedTask;
}, TimeSpan.Zero);
saver.Schedule(new ProjectSettings { HeroFrame = 1 });
Assert.False(await saver.FlushAsync());
Assert.True(await saver.HoldAsync(), "the failed change still waits");
fail = false;
var tried = attempts;
// Neither the retry (2 s after the failure) nor a flush writes while the user is asked.
var flush = saver.FlushAsync();
await Task.Delay(2500);
Assert.Equal(tried, attempts, "no write while held");
Assert.False(flush.IsCompleted);
saver.Release();
Assert.True(await flush.WaitAsync(TimeSpan.FromSeconds(10)), "kept: stored once released");
Assert.SequenceEqual([(int?)1], stored);
}
[Test]
public async Task ADiscardedChangeIsNeverWrittenEvenWhenTheArchiveComesBack()
{
var fail = true;
var stored = new List<int?>();
var saver = new ProjectSaver(p =>
{
if (fail) throw new System.IO.IOException("offline");
stored.Add(p.HeroFrame);
return Task.CompletedTask;
}, TimeSpan.Zero);
saver.Schedule(new ProjectSettings { HeroFrame = 3 });
Assert.False(await saver.FlushAsync());
Assert.True(await saver.HoldAsync());
// The archive answers again while the question is open; the user then discards the change.
fail = false;
await Task.Delay(2500);
saver.Stop();
Assert.True(await saver.FlushAsync().WaitAsync(TimeSpan.FromSeconds(10)));
Assert.Count(0, stored, "the discarded change was never written");
}
[Test]
public async Task AHoldWaitsForTheWriteUnderWay()
{
var gate = new TaskCompletionSource();
var started = new TaskCompletionSource();
var saver = new ProjectSaver(async _ =>
{
started.TrySetResult();
await gate.Task;
}, TimeSpan.Zero);
saver.Schedule(new ProjectSettings { HeroFrame = 1 });
await started.Task.WaitAsync(TimeSpan.FromSeconds(10));
var hold = saver.HoldAsync();
Assert.False(hold.IsCompleted, "the write under way may still fail");
gate.SetResult();
Assert.False(await hold.WaitAsync(TimeSpan.FromSeconds(10)), "it stored the change: nothing to ask");
saver.Release();
}
[Test]
public async Task FlushWithNothingPendingIsStored()
{
var saver = new ProjectSaver(_ => Task.CompletedTask, TimeSpan.FromMinutes(5));
Assert.True(await saver.FlushAsync().WaitAsync(TimeSpan.FromSeconds(10)));
}
[Test]
public async Task AChangeDuringAWriteIsWrittenAfterIt()
{
var gate = new TaskCompletionSource();
var saved = new List<int?>();
var saver = new ProjectSaver(async p =>
{
saved.Add(p.HeroFrame);
if (saved.Count == 1) await gate.Task;
}, TimeSpan.Zero);
saver.Schedule(new ProjectSettings { HeroFrame = 1 });
while (saved.Count == 0) await Task.Delay(5);
saver.Schedule(new ProjectSettings { HeroFrame = 2 });
saver.Schedule(new ProjectSettings { HeroFrame = 3 });
gate.SetResult();
await saver.FlushAsync();
Assert.SequenceEqual([(int?)1, 3], saved);
}
}