- NOTICE: copyright, GPL-3.0-only, and three additional terms of the kinds section 7 permits - (b) preserve the notices and the attribution in the program's legal notices, (c) mark a modified version as different and do not call it "FrameLedger" alone, (e) no trademark rights in the name. Shipped as licenses\NOTICE.txt; release.yml refuses a published tree without it. - Section 7 wants additional terms named in the source files: every first-party .cs .cpp .h .inl .ps1 .xaml file (1,053; src/native/third_party excluded) opens with the SPDX line and a pointer to NOTICE. tools/notice-check.ps1 is the gate (six self-test cases, both directions; -Fix writes a missing header) and tools/resx-gen.ps1 generates the string accessors with the header. - The native VERSIONINFO LegalCopyright said GPL-3.0-or-later; it now names the real licence. - CONTRIBUTING.md, FORKING.md, CODE_OF_CONDUCT.md (Contributor Covenant 2.1 by reference), legal/TRADEMARKS.md. - 12_BUILD gate list, CLAUDE.md layout and conventions. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.6 KiB
C#
62 lines
2.6 KiB
C#
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
|
|
|
using System.Diagnostics;
|
|
using FluentAssertions;
|
|
using FrameLedger.Infrastructure.Persistence;
|
|
|
|
namespace FrameLedger.Infrastructure.Tests.Persistence;
|
|
|
|
/// <summary>
|
|
/// The migration mutex is the ledger file's, not the session's (2026-09-17). With one name for every ledger, a test process
|
|
/// that froze mid-migration — <c>Infrastructure.Tests</c> on #199's run — held every other process's scratch ledger, and
|
|
/// seven App and Agent tests failed after 30 s with "another process has been migrating the ledger".
|
|
/// </summary>
|
|
public sealed class MigrationLockTests
|
|
{
|
|
private static CancellationToken Ct => TestContext.Current.CancellationToken;
|
|
|
|
[Fact]
|
|
public void EachLedgerFileHasItsOwnNameHoweverItIsSpelled()
|
|
{
|
|
string a = Path.Combine(Path.GetTempPath(), "fl-migrate-a", LedgerPaths.DatabaseFileName);
|
|
string b = Path.Combine(Path.GetTempPath(), "fl-migrate-b", LedgerPaths.DatabaseFileName);
|
|
|
|
MigrationRunner.LockNameFor(a).Should().StartWith(@"Local\FrameLedger.Ledger.Migrate.").And.NotBe(MigrationRunner.LockNameFor(b));
|
|
MigrationRunner.LockNameFor(a.ToUpperInvariant()).Should().Be(MigrationRunner.LockNameFor(a));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AMigrationHeldOnOneLedgerDoesNotHoldAnother()
|
|
{
|
|
// A thread that takes another ledger's lock and keeps it stands in for the frozen process.
|
|
string other = Path.Combine(Path.GetTempPath(), "fl-migrate-held-" + Guid.NewGuid().ToString("N"), LedgerPaths.DatabaseFileName);
|
|
using var taken = new ManualResetEventSlim();
|
|
using var release = new ManualResetEventSlim();
|
|
var holder = new Thread(() =>
|
|
{
|
|
using var mutex = new Mutex(initiallyOwned: false, MigrationRunner.LockNameFor(other));
|
|
mutex.WaitOne();
|
|
taken.Set();
|
|
release.Wait();
|
|
mutex.ReleaseMutex();
|
|
})
|
|
{ IsBackground = true };
|
|
holder.Start();
|
|
taken.Wait(Ct);
|
|
try
|
|
{
|
|
var clock = Stopwatch.StartNew();
|
|
await using LedgerFixture f = await LedgerFixture.OpenAsync().ConfigureAwait(true);
|
|
|
|
clock.Elapsed.Should().BeLessThan(TimeSpan.FromSeconds(15), "another ledger's migration is not this one's; one shared name waited 30 s and threw");
|
|
f.Db.SchemaVersion.Should().Be(MigrationRunner.LatestVersion);
|
|
}
|
|
finally
|
|
{
|
|
release.Set();
|
|
holder.Join();
|
|
}
|
|
}
|
|
}
|