CI / Build and test (push) Successful in 13m44s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 16s
Release / Build, test and publish (push) Successful in 26m34s
CI / PostgreSQL 16 integration (push) Failing after 17m36s
CI / PostgreSQL 17 integration (push) Failing after 15m36s
CI / Docker image (push) Successful in 1m12s
Release / Server image (push) Failing after 15s
The same time-lapse on a server and on this PC under different ids, or twice on this PC, is recognised, compared and settled as the owner asked in owner review 6. Matches are found after each sync refresh, through the server's new photo lookup, and after the jobs that change photos. The default is to ask every time. Server › Matches offers: - Keep apart, which is remembered; - Link only and Unlink; - the Compare dialog: photos, details line by line, projects and the plan. Integrate completes both sides. Photos default to Union, projects are copied across, and a losing version goes to the trash only after a hash check. Afterwards new photos move by themselves, and deletions wait for the user. A merge of two local sequences verifies every photo before the other sequence goes to its archive's trash. Upload all local skips suspected matches and flags them. Migration 0012 adds the found_copies and copy_probes tables. Jobs 25 (Integrate) and 26 (MergeSequences) are new, and so are the server capabilities photo-lookup and upload-into. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
160 lines
7.6 KiB
C#
160 lines
7.6 KiB
C#
using System.IO;
|
|
using Chronos.App.Server;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Data.Archiving.Jobs;
|
|
using Chronos.Data.Workspaces;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.App.Tests.Server;
|
|
|
|
/// <summary>
|
|
/// Which jobs "Pause metered transfers" holds (Server.html, phase 5c): uploads, the sync's downloads, and the workspace's copies from and renders
|
|
/// sent to a server, and the integrations of pairs with a server sequence; never a copy from or a send to this PC's archive, nor a merge.
|
|
/// </summary>
|
|
public sealed class UploadHoldTests
|
|
{
|
|
private const string Server = "https://nas.local:8443";
|
|
private static readonly Guid SequenceId = Guid.CreateVersion7();
|
|
private static readonly Guid ProjectId = Guid.CreateVersion7();
|
|
private const string Root = @"C:\Users\me\Chronos\workspace";
|
|
|
|
private static Job Of(ArchiveJobRequest request) => new()
|
|
{
|
|
Id = Guid.CreateVersion7(),
|
|
Kind = request.Kind,
|
|
TargetIds = request.Targets,
|
|
TargetLabel = request.Label,
|
|
ParametersJson = request.ParametersJson,
|
|
State = JobState.Queued,
|
|
Created = DateTimeOffset.UtcNow,
|
|
};
|
|
|
|
private static Job Of(JobKind kind, string? parameters = null) => new()
|
|
{
|
|
Id = Guid.CreateVersion7(),
|
|
Kind = kind,
|
|
TargetIds = [SequenceId],
|
|
ParametersJson = parameters,
|
|
State = JobState.Queued,
|
|
Created = DateTimeOffset.UtcNow,
|
|
};
|
|
|
|
[Test]
|
|
public void TransfersWithAServerAreHeld()
|
|
{
|
|
Assert.True(UploadHold.Holds(Of(JobKind.UploadCommit)));
|
|
// The sync's downloads too: the option's tooltip says "uploads and downloads".
|
|
Assert.True(UploadHold.Holds(Of(JobKind.Download)));
|
|
Assert.True(UploadHold.Holds(Of(WorkspaceJobs.CopyFromServer(SequenceId, "Harbour", Server, Root, ProjectId))));
|
|
Assert.True(UploadHold.Holds(Of(WorkspaceJobs.Send(SequenceId, "Harbour", Root, ProjectId, [], Server))));
|
|
Assert.SequenceEqual([JobKind.UploadCommit, JobKind.Download, JobKind.WorkspaceCopy, JobKind.WorkspaceSend, JobKind.Integrate], UploadHold.Kinds);
|
|
}
|
|
|
|
[Test]
|
|
public void AnIntegrationIsHeldAMergeIsNot()
|
|
{
|
|
// An integration always moves photos with a server (owner review 6, #73); a merge of two local sequences never does.
|
|
Assert.True(UploadHold.Holds(Of(JobKind.Integrate)));
|
|
Assert.False(UploadHold.Holds(Of(JobKind.MergeSequences)));
|
|
}
|
|
|
|
[Test]
|
|
public void AnAutomaticTransferIsHeldOnAMeteredConnectionWithTheOptionOff()
|
|
{
|
|
// Owner review 6, Q6: new photos of an integrated pair move by themselves, "paused on metered connections".
|
|
var automatic = Of(JobKind.Download, $$"""{"server":"{{Server}}","mode":"Originals","automatic":true}""");
|
|
var manual = Of(JobKind.Download, $$"""{"server":"{{Server}}","mode":"Originals"}""");
|
|
Assert.True(Chronos.Data.Sync.SyncService.IsAutomaticTransfer(automatic));
|
|
Assert.False(Chronos.Data.Sync.SyncService.IsAutomaticTransfer(manual));
|
|
|
|
Assert.True(UploadHold.HeldNow(automatic, metered: true, optionOn: false));
|
|
Assert.False(UploadHold.HeldNow(manual, metered: true, optionOn: false));
|
|
Assert.True(UploadHold.HeldNow(manual, metered: true, optionOn: true));
|
|
Assert.False(UploadHold.HeldNow(automatic, metered: false, optionOn: true));
|
|
// An automatic upload too.
|
|
Assert.True(UploadHold.HeldNow(Of(JobKind.UploadCommit, $$"""{"server":"{{Server}}","automatic":true}"""), metered: true, optionOn: false));
|
|
}
|
|
|
|
/// <summary>A fresh index in a temporary folder and its job engine (not started).</summary>
|
|
private static async Task HoldScenarioAsync(Func<Chronos.Data.ChronosDatabase, Chronos.Data.Jobs.JobEngine, Task> body)
|
|
{
|
|
var folder = Path.Combine(Path.GetTempPath(), "chronos-hold-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(folder);
|
|
try
|
|
{
|
|
await using var db = await Chronos.Data.ChronosDatabase.OpenAsync(Chronos.Data.DatabaseOptions.Sqlite(Path.Combine(folder, "index.db")));
|
|
await using var engine = new Chronos.Data.Jobs.JobEngine(db, [], new Chronos.Data.Jobs.JobEngineOptions { Workers = 1, WorkerId = "test" });
|
|
await body(db, engine);
|
|
}
|
|
finally
|
|
{
|
|
try
|
|
{
|
|
Directory.Delete(folder, recursive: true);
|
|
}
|
|
catch (IOException)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public Task ATransferTheHoldPausedBeforeARestartResumesOnceTheConnectionIsNotMetered() => HoldScenarioAsync(async (db, engine) =>
|
|
{
|
|
var automatic = Of(JobKind.Download, $$"""{"server":"{{Server}}","mode":"Originals","automatic":true}""");
|
|
var userPaused = Of(JobKind.Download, $$"""{"server":"{{Server}}","mode":"Originals","automatic":true}""");
|
|
await db.Jobs.EnqueueAsync(automatic);
|
|
await db.Jobs.EnqueueAsync(userPaused);
|
|
// The user paused this one before the connection became metered: the hold never paused it.
|
|
await db.Jobs.SetStateAsync(userPaused.Id, JobState.Paused, null);
|
|
using (var before = new UploadHold(() => db, () => false, () => true))
|
|
{
|
|
before.Attach(engine);
|
|
await before.ApplyAsync();
|
|
Assert.Equal(JobState.Paused, (await db.Jobs.GetAsync(automatic.Id))!.State);
|
|
}
|
|
|
|
// A new hold after a restart reads the record the first one kept in the index.
|
|
using var hold = new UploadHold(() => db, () => false, () => false);
|
|
hold.Attach(engine);
|
|
await hold.ApplyAsync();
|
|
|
|
Assert.Equal(JobState.Queued, (await db.Jobs.GetAsync(automatic.Id))!.State);
|
|
// An automatic transfer the user paused stays paused: the hold resumes only what it paused.
|
|
Assert.Equal(JobState.Paused, (await db.Jobs.GetAsync(userPaused.Id))!.State);
|
|
Assert.Equal("[]", await db.Settings.GetJsonAsync(Chronos.Data.Repositories.SettingScope.App, null, UploadHold.RecordKey));
|
|
});
|
|
|
|
[Test]
|
|
public Task AJobTheUserPausesWhileHeldIsNeverResumedByTheHold() => HoldScenarioAsync(async (db, engine) =>
|
|
{
|
|
var automatic = Of(JobKind.UploadCommit, $$"""{"server":"{{Server}}","automatic":true}""");
|
|
await db.Jobs.EnqueueAsync(automatic);
|
|
var metered = true;
|
|
using var hold = new UploadHold(() => db, () => false, () => metered);
|
|
hold.Attach(engine);
|
|
await hold.ApplyAsync();
|
|
Assert.Equal(JobState.Paused, (await db.Jobs.GetAsync(automatic.Id))!.State);
|
|
|
|
// The user pauses it from Jobs (the queue tells the hold), then the connection is no longer metered.
|
|
using var queue = new Chronos.App.Jobs.EngineJobQueue(db, engine, started: false, acted: id => hold.ForgetAsync(id).GetAwaiter().GetResult());
|
|
await queue.PauseAsync(automatic.Id);
|
|
metered = false;
|
|
await hold.ApplyAsync();
|
|
|
|
Assert.Equal(JobState.Paused, (await db.Jobs.GetAsync(automatic.Id))!.State);
|
|
});
|
|
|
|
[Test]
|
|
public void TransfersWithThisPcsLibraryAndOtherJobsAreNot()
|
|
{
|
|
var sequence = new Sequence { Id = SequenceId, ArchiveId = Guid.CreateVersion7(), Title = "Harbour", Folder = "2026/harbour" };
|
|
Assert.False(UploadHold.Holds(Of(WorkspaceJobs.Copy(sequence, Root, ProjectId))));
|
|
Assert.False(UploadHold.Holds(Of(WorkspaceJobs.Send(SequenceId, "Harbour", Root, ProjectId, []))));
|
|
Assert.False(UploadHold.Holds(Of(JobKind.Render)));
|
|
// Parameters that cannot be read are not held: the job fails with its reason.
|
|
Assert.False(UploadHold.Holds(Of(JobKind.WorkspaceSend, "{not json")));
|
|
Assert.False(UploadHold.Holds(Of(JobKind.WorkspaceCopy)));
|
|
}
|
|
}
|