CI / Build and test (pull_request) Failing after 2m3s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / Docker image (pull_request) Skipped
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 4s
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. 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) and pe-check. 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>
112 lines
3.8 KiB
C#
112 lines
3.8 KiB
C#
using System.Collections.Concurrent;
|
|
using System.Text;
|
|
|
|
namespace Chronos.Testing;
|
|
|
|
/// <summary>
|
|
/// Per-test services. A test class may take a <see cref="TestContext"/> in its constructor;
|
|
/// one context is created for every test execution and disposed after it.
|
|
/// </summary>
|
|
public sealed class TestContext : IDisposable
|
|
{
|
|
private static readonly AsyncLocal<TestContext?> CurrentTest = new();
|
|
private readonly ConcurrentQueue<string> _log = new();
|
|
private readonly List<string> _tempDirectories = [];
|
|
private readonly Lock _gate = new();
|
|
|
|
internal TestContext(string testName, bool isSerial, CancellationToken cancellation)
|
|
{
|
|
TestName = testName;
|
|
IsSerial = isSerial;
|
|
Cancellation = cancellation;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The test running on this flow of execution (its constructor, body and the tasks it starts); null outside tests.
|
|
/// Lets a test program guard process-wide state, which only a serial test may change.
|
|
/// </summary>
|
|
public static TestContext? Current
|
|
{
|
|
get => CurrentTest.Value;
|
|
internal set => CurrentTest.Value = value;
|
|
}
|
|
|
|
public string TestName { get; }
|
|
|
|
/// <summary>True when the test's class is <see cref="SerialAttribute"/>: no other test runs beside it.</summary>
|
|
public bool IsSerial { get; }
|
|
|
|
/// <summary>Signalled when the test times out or the run is aborted.</summary>
|
|
public CancellationToken Cancellation { get; }
|
|
|
|
/// <summary>Repository root (the directory that holds <c>Chronos.slnx</c>), or the working directory.</summary>
|
|
public static string RepositoryRoot { get; } = FindRepositoryRoot();
|
|
|
|
/// <summary><c>tests/fixtures</c> under the repository root.</summary>
|
|
public static string FixturesDirectory => Path.Combine(RepositoryRoot, "tests", "fixtures");
|
|
|
|
/// <summary>Creates an empty directory that is deleted when the test ends.</summary>
|
|
public string CreateTempDirectory(string? hint = null)
|
|
{
|
|
var path = Path.Combine(Path.GetTempPath(), "chronos-tests", $"{Sanitize(hint ?? TestName)}-{Guid.NewGuid():N}");
|
|
Directory.CreateDirectory(path);
|
|
lock (_gate) _tempDirectories.Add(path);
|
|
return path;
|
|
}
|
|
|
|
/// <summary>Lines written here are printed only when the test fails or in verbose mode.</summary>
|
|
public void Log(string message) => _log.Enqueue(message);
|
|
|
|
public string LogText
|
|
{
|
|
get
|
|
{
|
|
var sb = new StringBuilder();
|
|
foreach (var line in _log) sb.AppendLine(line);
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
|
|
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
|
|
public static void Skip(string reason) => throw new SkipException(reason);
|
|
|
|
public void Dispose()
|
|
{
|
|
lock (_gate)
|
|
{
|
|
foreach (var dir in _tempDirectories)
|
|
{
|
|
try
|
|
{
|
|
if (Directory.Exists(dir)) Directory.Delete(dir, recursive: true);
|
|
}
|
|
catch (IOException)
|
|
{
|
|
// Best effort: a file still open by the OS indexer must not fail the test.
|
|
}
|
|
catch (UnauthorizedAccessException)
|
|
{
|
|
}
|
|
}
|
|
_tempDirectories.Clear();
|
|
}
|
|
}
|
|
|
|
private static string Sanitize(string s)
|
|
{
|
|
var chars = s.Select(c => char.IsLetterOrDigit(c) ? c : '-').Take(48).ToArray();
|
|
return new string(chars);
|
|
}
|
|
|
|
private static string FindRepositoryRoot()
|
|
{
|
|
var dir = new DirectoryInfo(AppContext.BaseDirectory);
|
|
while (dir is not null)
|
|
{
|
|
if (File.Exists(Path.Combine(dir.FullName, "Chronos.slnx"))) return dir.FullName;
|
|
dir = dir.Parent;
|
|
}
|
|
return Directory.GetCurrentDirectory();
|
|
}
|
|
}
|