feat: single setup, mass-pass progress, per-server homes, Desktop shares its library (owner review 5, v1.1.0) (#68)
CI / Build and test (push) Successful in 11m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 12s
Release / Build, test and publish (push) Successful in 14m56s
CI / PostgreSQL 16 integration (push) Successful in 10m11s
CI / PostgreSQL 17 integration (push) Successful in 10m15s
CI / Docker image (push) Successful in 45s
Release / Server image (push) Successful in 4m55s
CI / Build and test (push) Successful in 11m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 12s
Release / Build, test and publish (push) Successful in 14m56s
CI / PostgreSQL 16 integration (push) Successful in 10m11s
CI / PostgreSQL 17 integration (push) Successful in 10m15s
CI / Docker image (push) Successful in 45s
Release / Server image (push) Successful in 4m55s
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #68.
This commit is contained in:
1 parent
988068ee8e
commit
20d64af4a4
793 files changed
+23882
-2096
No files matched your search
@@ -0,0 +1,58 @@
|
||||
using Chronos.Core.IO;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Data.Tests.Homes;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Data.Tests.Sync;
|
||||
|
||||
/// <summary>Where the proxies of a server's sequence live (owner review 5, #66): its home in the cache, else where an earlier layout left them.</summary>
|
||||
[Category("sync")]
|
||||
public sealed class ProxyCacheTests(TestContext context)
|
||||
{
|
||||
private static readonly Guid Id = Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a01");
|
||||
|
||||
[Test]
|
||||
public void WithoutAServersRootTheLayoutIs10s()
|
||||
{
|
||||
var root = context.CreateTempDirectory("proxies");
|
||||
var remote = Guid.CreateVersion7();
|
||||
var cache = new ProxyCache(root);
|
||||
Assert.Equal(Path.Combine(root, HomeFolders.AddressHash(HomeFixtures.Nas), remote.ToString("N")), cache.Folder(HomeFixtures.Nas, remote));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ANewSequenceGoesToItsServersHomeAndAnOldOneIsReadWhereItIs()
|
||||
{
|
||||
var cacheRoot = context.CreateTempDirectory("cache");
|
||||
var (legacyRoot, servers) = (Path.Combine(cacheRoot, "proxies"), Path.Combine(cacheRoot, "servers"));
|
||||
var identity = new ServerIdentity([new KnownServerKey(Id, [HomeFixtures.Nas])]);
|
||||
var cache = new ProxyCache(legacyRoot, servers, () => identity);
|
||||
var idKey = ServerIdentity.IdKey(Id);
|
||||
|
||||
var fresh = Guid.CreateVersion7();
|
||||
Assert.Equal(Path.Combine(servers, Id.ToString("N"), "proxies", fresh.ToString("N")), cache.Folder(idKey, fresh));
|
||||
Assert.Equal(cache.Folder(idKey, fresh), cache.Folder(HomeFixtures.Nas, fresh), "an alias names the same home");
|
||||
|
||||
// A sequence cached by 1.0 under the address is used where it is until it is moved.
|
||||
var old = Guid.CreateVersion7();
|
||||
var legacy = HomeFixtures.LegacyProxies(cacheRoot, HomeFixtures.Nas, old);
|
||||
Assert.Equal(legacy, cache.Folder(idKey, old));
|
||||
Assert.True(cache.Exists(idKey, old));
|
||||
|
||||
// In the home of the address (sorted before the server announced its id): used there too.
|
||||
var sorted = Guid.CreateVersion7();
|
||||
var byAddress = Path.Combine(servers, HomeFolders.ServerFolder(HomeFixtures.Nas), "proxies", sorted.ToString("N"));
|
||||
Directory.CreateDirectory(byAddress);
|
||||
Assert.Equal(byAddress, cache.Folder(idKey, sorted));
|
||||
|
||||
// Once in its home, that is where it is.
|
||||
var home = Path.Combine(servers, Id.ToString("N"), "proxies", old.ToString("N"));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(home)!);
|
||||
Directory.Move(legacy, home);
|
||||
Assert.Equal(home, cache.Folder(HomeFixtures.Nas, old));
|
||||
|
||||
// A server known by its address only has an address home.
|
||||
var other = Guid.CreateVersion7();
|
||||
Assert.Equal(Path.Combine(servers, HomeFolders.ServerFolder(HomeFixtures.Other), "proxies", other.ToString("N")), cache.Folder(HomeFixtures.Other, other));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using Chronos.Core.IO;
|
||||
using Chronos.Data.Projects;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Data.Tests.Sync;
|
||||
|
||||
/// <summary>How the desktop names a server (owner review 5, #66): by its announced id, its address keys kept as aliases.</summary>
|
||||
[Category("sync")]
|
||||
public sealed class ServerIdentityTests
|
||||
{
|
||||
private static readonly Guid Id = Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a01");
|
||||
|
||||
private static ServerInfo Info(Guid? id) => new("Studio NAS", "1.1.0", 1, [], null, [], new ServerLimits(1, 1), null, null, id);
|
||||
|
||||
[Test]
|
||||
public void AServerThatAnnouncesAnIdIsKeyedByIt()
|
||||
{
|
||||
var key = ServerIdentity.Key(Info(Id), new Uri("https://NAS.local:8443/"));
|
||||
Assert.Equal("id:" + Id.ToString("N"), key);
|
||||
Assert.True(ServerIdentity.IsIdKey(key));
|
||||
Assert.Equal(Id, ServerIdentity.IdOf(key));
|
||||
// Another address of the same server: the same key.
|
||||
Assert.Equal(key, ServerIdentity.Key(Info(Id), new Uri("https://192.168.1.5:8443")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnOlderServerKeepsItsAddressKey()
|
||||
{
|
||||
var address = new Uri("https://NAS.local:8443/");
|
||||
Assert.Equal("https://nas.local:8443", ServerIdentity.Key(Info(null), address));
|
||||
Assert.Equal(SyncService.ServerKey(address), ServerIdentity.Key((ServerInfo?)null, address));
|
||||
Assert.Equal(SyncService.ServerKey(address), ServerIdentity.Key(Guid.Empty, address));
|
||||
Assert.False(ServerIdentity.IsIdKey(SyncService.ServerKey(address)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AliasesNameTheServerOfTheirId()
|
||||
{
|
||||
var identity = new ServerIdentity([new KnownServerKey(Id, ["https://nas.local:8443", "https://192.168.1.5:8443"])]);
|
||||
var key = ServerIdentity.IdKey(Id);
|
||||
Assert.Equal(key, identity.Canonical("https://NAS.local:8443"));
|
||||
Assert.Equal(key, identity.Canonical(key.ToUpperInvariant()));
|
||||
Assert.Equal("https://other:1", identity.Canonical("https://other:1"));
|
||||
Assert.True(identity.Same("https://nas.local:8443", "https://192.168.1.5:8443"));
|
||||
Assert.True(identity.Same(key, "https://192.168.1.5:8443"));
|
||||
Assert.False(identity.Same(key, "https://other:1"));
|
||||
Assert.True(identity.Same(null, null));
|
||||
Assert.False(identity.Same(key, null));
|
||||
Assert.Equal(Id.ToString("N"), identity.FolderName("https://192.168.1.5:8443"));
|
||||
Assert.Equal(HomeFolders.ServerFolder("https://other:1"), identity.FolderName("https://other:1"));
|
||||
Assert.SequenceEqual(new[] { key, "https://nas.local:8443", "https://192.168.1.5:8443" }, identity.KeysOf("https://192.168.1.5:8443"));
|
||||
Assert.SequenceEqual(new[] { "https://other:1" }, identity.KeysOf("https://other:1"));
|
||||
Assert.Equal(2, identity.AliasesOf(Id).Count);
|
||||
|
||||
// Without the table every key is its own.
|
||||
Assert.False(ServerIdentity.None.Same(key, "https://nas.local:8443"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnAddressChangeKeepsTheKeyOnceTheAliasIsKnown()
|
||||
{
|
||||
var identity = new ServerIdentity([new KnownServerKey(Id, ["https://nas.local:8443"])]);
|
||||
var widened = identity.With(Id, "https://nas.local:9443");
|
||||
Assert.True(widened.Same("https://nas.local:8443", "https://nas.local:9443"));
|
||||
Assert.Same(widened, widened.With(Id, "HTTPS://nas.local:9443"));
|
||||
Assert.False(identity.Same("https://nas.local:8443", "https://nas.local:9443"), "the table it came from is unchanged");
|
||||
var other = Guid.CreateVersion7();
|
||||
Assert.Equal(ServerIdentity.IdKey(other), widened.With(other, "https://second:1").Canonical("https://second:1"));
|
||||
// An address two ids claim stays with the first one listed.
|
||||
var clash = new ServerIdentity([new KnownServerKey(Id, ["https://x"]), new KnownServerKey(other, ["https://x"])]);
|
||||
Assert.Equal(ServerIdentity.IdKey(Id), clash.Canonical("https://x"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheArchiveIdOfAnyAliasIsTheServers()
|
||||
{
|
||||
string[] keys = [ServerIdentity.IdKey(Id), "https://nas.local:8443"];
|
||||
Assert.True(ServerProjectHome.IsArchiveIdOf(ServerProjectHome.ArchiveIdOf("https://nas.local:8443"), keys));
|
||||
Assert.True(ServerProjectHome.IsArchiveIdOf(ServerProjectHome.ArchiveIdOf(keys[0]), keys));
|
||||
Assert.False(ServerProjectHome.IsArchiveIdOf(ServerProjectHome.ArchiveIdOf("https://other:1"), keys));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user