Setup: a kept 1.0 Uploader no longer fixes the scope and folder, the Remove tooltip promises kept files only with a hashed log, and a single-program setup preselects it. The Uploader always downloads the setup. Sync links move to the server id at every sign-in while folders wait for jobs and open editors; jobs of a pending homes sort still find their projects. A shared library exposes only the shared archive's client-visible jobs and events, render nodes take only client renders, and the share counts as its own while starting. Progress: a new step waits a quarter interval and a trailing timer publishes the last state; the job bar tooltip carries the whole line; Recent maintenance and the Server jobs list pick up jobs that start while they are shown. Refs #64 #65 #66 #67 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
5.3 KiB
C#
103 lines
5.3 KiB
C#
using Chronos.Core.IO;
|
|
using Chronos.Data.Homes;
|
|
using Chronos.Data.Sync;
|
|
using Chronos.Data.Tests.Infrastructure;
|
|
using Chronos.Data.Tests.Repositories;
|
|
using Chronos.Data.Workspaces;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Sync;
|
|
|
|
/// <summary>A server's links move from its address key to its id key (owner review 5, #66), the newer row winning a clash.</summary>
|
|
[Category("sync")]
|
|
public abstract class SyncLinkRekeyTests(TestContext context) : RepositoryTest(context)
|
|
{
|
|
private const string Address = "https://nas.local:8443";
|
|
private static readonly string IdKey = ServerIdentity.IdKey(Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a01"));
|
|
|
|
private static SyncLink Link(string server, Guid remoteId, Guid? localId, DateTimeOffset? synced, string title = "Harbour") => new()
|
|
{
|
|
Server = server,
|
|
RemoteId = remoteId,
|
|
LocalId = localId,
|
|
Title = title,
|
|
RemoteUpdatedAt = TestData.Now,
|
|
SyncedAt = synced,
|
|
};
|
|
|
|
[Test]
|
|
public async Task TheLinksOfAnAddressMoveToTheIdAndTheNewerRowWinsAClash()
|
|
{
|
|
var db = await OpenChronosAsync();
|
|
var archive = TestData.Archive();
|
|
await db.Archives.UpsertAsync(archive, Ct);
|
|
var (a, b, c) = (TestData.Sequence(archive.Id), TestData.Sequence(archive.Id), TestData.Sequence(archive.Id));
|
|
foreach (var sequence in new[] { a, b, c }) await db.Sequences.UpsertAsync(sequence, Ct);
|
|
var store = new SyncLinkStore(db);
|
|
var (plain, sameRemote, sameLocal, stale) = (Guid.CreateVersion7(), Guid.CreateVersion7(), Guid.CreateVersion7(), Guid.CreateVersion7());
|
|
// Only under the address: it moves.
|
|
await store.UpsertAsync(Link(Address, plain, a.Id, TestData.Now), Ct);
|
|
// Under both keys for one server sequence: the address's row is newer, so it replaces the id's.
|
|
await store.UpsertAsync(Link(Address, sameRemote, null, TestData.Now.AddHours(2), "newer"), Ct);
|
|
await store.UpsertAsync(Link(IdKey, sameRemote, null, TestData.Now.AddHours(1), "older"), Ct);
|
|
// Both keys link local copy b to different server sequences: the id's row is newer, so the address's goes.
|
|
await store.UpsertAsync(Link(Address, sameLocal, b.Id, TestData.Now), Ct);
|
|
await store.UpsertAsync(Link(IdKey, Guid.CreateVersion7(), b.Id, TestData.Now.AddDays(1)), Ct);
|
|
// Never compared under the address, compared under the id: the id's stays.
|
|
await store.UpsertAsync(Link(Address, stale, c.Id, null), Ct);
|
|
await store.UpsertAsync(Link(IdKey, stale, null, TestData.Now), Ct);
|
|
|
|
var (moved, dropped) = await store.RekeyAsync(Address, IdKey, Ct);
|
|
Assert.Equal((2, 3), (moved, dropped));
|
|
Assert.Empty(await store.ListAsync(Address, Ct));
|
|
var links = (await store.ListAsync(IdKey, Ct)).ToDictionary(l => l.RemoteId);
|
|
Assert.Equal(4, links.Count);
|
|
Assert.Equal(a.Id, links[plain].LocalId);
|
|
Assert.Equal("newer", links[sameRemote].Title);
|
|
Assert.False(links.ContainsKey(sameLocal));
|
|
Assert.Null(links[stale].LocalId);
|
|
Assert.Equal(b.Id, Assert.NotNull(await store.FindByLocalAsync(IdKey, b.Id, Ct)).LocalId);
|
|
|
|
// Again: nothing left to move; and a key onto itself does nothing.
|
|
Assert.Equal((0, 0), await store.RekeyAsync(Address, IdKey, Ct));
|
|
Assert.Equal((0, 0), await store.RekeyAsync(IdKey, IdKey, Ct));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TheLinksMoveToTheIdWhileTheFoldersWait()
|
|
{
|
|
var db = await OpenChronosAsync();
|
|
var archive = TestData.Archive();
|
|
await db.Archives.UpsertAsync(archive, Ct);
|
|
var sequence = TestData.Sequence(archive.Id);
|
|
await db.Sequences.UpsertAsync(sequence, Ct);
|
|
var store = new SyncLinkStore(db);
|
|
var remote = Guid.CreateVersion7();
|
|
await store.UpsertAsync(Link(Address, remote, sequence.Id, TestData.Now), Ct);
|
|
var data = Context.CreateTempDirectory("data");
|
|
var workspace = new WorkspaceHomes(Path.Combine(data, "workspace"));
|
|
var home = Path.Combine(workspace.Root, "servers", HomeFolders.ServerFolder(Address));
|
|
Directory.CreateDirectory(home);
|
|
var migration = new HomeLayoutMigration(new HomeLayoutOptions { DataDirectory = data, WorkspaceRoot = workspace.Root, Database = db });
|
|
|
|
// A download or an upload resumed under the id key finds its link before the folders move (a job held them).
|
|
var id = ServerIdentity.IdOf(IdKey)!.Value;
|
|
Assert.Equal((1, 0), await migration.RekeyLinksAsync(id, [Address, IdKey], Ct));
|
|
Assert.Equal(sequence.Id, Assert.NotNull(await store.GetAsync(IdKey, remote, Ct)).LocalId);
|
|
Assert.Equal(sequence.Id, Assert.NotNull(await store.FindByLocalAsync(IdKey, sequence.Id, Ct)).LocalId);
|
|
Assert.Empty(await store.ListAsync(Address, Ct));
|
|
Assert.True(Directory.Exists(home), "the folders wait for the full re-key");
|
|
Assert.Equal((0, 0), await migration.RekeyLinksAsync(id, [Address], Ct));
|
|
}
|
|
}
|
|
|
|
public sealed class SqliteSyncLinkRekeyTests(TestContext context) : SyncLinkRekeyTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.SqliteMemory;
|
|
}
|
|
|
|
public sealed class PostgresSyncLinkRekeyTests(TestContext context) : SyncLinkRekeyTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.Postgres;
|
|
}
|