A kept dry run was keyed on a stamp of every sequence row of the archive, updated_at and verified_at included, so any upload, ingest status write, verify or tag edit anywhere invalidated it and the confirm planned the whole selection again. The plan was also bound to the request, so a proxy cutting the request off cancelled it and a retry started over. - The stamp (SequenceRepository.GetStampAsync) now hashes only what the planner reads from the index: every row's id and folder (collisions and what a moving folder carries), the planned rows' title, first capture, camera, lens, photo count and frames version, and the titles of the rows inside a planned folder. With all, every row is planned. - ReorganizePlanCache makes a plan on the thread pool with the host's stopping token, once per key for concurrent requests; a request cut off only stops waiting, and the same request again waits for the plan or takes it. Refusals and failures are still not kept. - A kept plan is dropped by its own timer five minutes after it was made (and never used past that), instead of staying until the next request. - The protocol and endpoint docs say that plan_changed answers changes the index has; one made on disk alone is found by the job, which fails and changes nothing. The Capacity doc no longer claims a step per sequence. - Tests: what the stamp follows and ignores, a kept plan surviving an upload elsewhere and a verify, one plan for concurrent requests and after a cut-off, the timer, an all:true apply carrying a nested sequence beside a blocked-only one, the first sequence told before a pause. The no-archive-module job_unavailable test expected a folder the planner no longer plans without a sidecar; it now expects the unreadable step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 7e01a4f85fe4b880ddd98a481fc8591649cec254)
92 lines
5.3 KiB
C#
92 lines
5.3 KiB
C#
using Chronos.Core.Model;
|
|
using Chronos.Data.Repositories;
|
|
using Chronos.Data.Tests.Infrastructure;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Repositories;
|
|
|
|
/// <summary>
|
|
/// The stamp of what a Reorganize plans from in an archive's index (<see cref="SequenceRepository.GetStampAsync"/>) on both
|
|
/// dialects: the server makes a kept Reorganize plan again once it is another one, and only then (owner review 2, R7).
|
|
/// </summary>
|
|
public abstract class SequenceStampTests(TestContext context) : RepositoryTest(context)
|
|
{
|
|
[Test]
|
|
public async Task TheStampFollowsWhatAReorganizePlansFromAndNothingElse()
|
|
{
|
|
var db = await OpenChronosAsync();
|
|
var archive = TestData.Archive();
|
|
var other = TestData.Archive("Other");
|
|
await db.Archives.UpsertAsync(archive, Ct);
|
|
await db.Archives.UpsertAsync(other, Ct);
|
|
var roof = TestData.Sequence(archive.Id, new DateTime(2026, 9, 28, 18, 0, 0), "Roof");
|
|
var inner = TestData.Sequence(archive.Id, null, "Inner") with { Folder = roof.Folder + "/inner" };
|
|
var ridge = TestData.Sequence(archive.Id, new DateTime(2026, 9, 29, 7, 0, 0), "Ridge");
|
|
IReadOnlyList<Guid> planned = [roof.Id];
|
|
var empty = await db.Sequences.GetStampAsync(archive.Id, planned, Ct);
|
|
foreach (var sequence in new[] { roof, inner, ridge }) await db.Sequences.UpsertAsync(sequence, Ct);
|
|
var stamp = await db.Sequences.GetStampAsync(archive.Id, planned, Ct);
|
|
Assert.NotEqual(empty, stamp);
|
|
Assert.Equal(stamp, await db.Sequences.GetStampAsync(archive.Id, planned, Ct));
|
|
Assert.NotEqual(stamp, await db.Sequences.GetStampAsync(archive.Id, null, Ct));
|
|
|
|
// What the plan does not read: another archive, and the writes of every upload, verify, tag or status change elsewhere.
|
|
await db.Sequences.UpsertAsync(TestData.Sequence(other.Id), Ct);
|
|
await PhotoAsync(db, ridge, 0);
|
|
await PhotoAsync(db, inner, 0);
|
|
Assert.Equal(SequenceEditOutcome.Updated, (await db.Sequences.EditAsync(ridge.Id, new SequenceEdit { Title = "Ridge at dawn", Notes = "cold" }, null, Ct)).Outcome);
|
|
foreach (var id in new[] { roof.Id, ridge.Id })
|
|
{
|
|
Assert.True(await db.Sequences.SetTagsAsync(id, ["sky"], Ct));
|
|
Assert.True(await db.Sequences.UpdateStatusAsync(id, SequenceStatus.ProxiesBuilt, SequenceStatus.None, Ct));
|
|
Assert.True(await db.Sequences.RecordVerifiedAsync(id, SequenceStatus.None, SequenceStatus.None, TestData.Now, Ct));
|
|
}
|
|
Assert.Equal(stamp, await db.Sequences.GetStampAsync(archive.Id, planned, Ct));
|
|
|
|
// What it reads gives one never seen before: the sequences planned, the titles inside their folders, every folder.
|
|
var seen = new HashSet<string>(StringComparer.Ordinal) { empty, stamp };
|
|
async Task ChangedAsync(string what) => Assert.True(seen.Add(await db.Sequences.GetStampAsync(archive.Id, planned, Ct)), what);
|
|
Assert.Equal(SequenceEditOutcome.Updated, (await db.Sequences.EditAsync(roof.Id, new SequenceEdit { Title = "Roof at noon" }, null, Ct)).Outcome);
|
|
await ChangedAsync("title");
|
|
await PhotoAsync(db, roof, 0);
|
|
await ChangedAsync("photos");
|
|
Assert.Equal(SequenceEditOutcome.Updated, (await db.Sequences.EditAsync(inner.Id, new SequenceEdit { Title = "Inner court" }, null, Ct)).Outcome);
|
|
await ChangedAsync("title of a sequence a moving folder would carry");
|
|
Assert.True(await db.Sequences.RelocateAsync(ridge.Id, "2026/ridge", null, Ct));
|
|
await ChangedAsync("folder of a sequence not planned");
|
|
Assert.True(await db.Sequences.RelocateAsync(roof.Id, "2026/moved", null, Ct));
|
|
await ChangedAsync("folder");
|
|
var added = TestData.Sequence(archive.Id);
|
|
await db.Sequences.UpsertAsync(added, Ct);
|
|
await ChangedAsync("a sequence added");
|
|
Assert.True(await db.Sequences.DeleteAsync(added.Id, Ct));
|
|
Assert.Contains(await db.Sequences.GetStampAsync(archive.Id, planned, Ct), seen);
|
|
|
|
// With every sequence planned, a photo anywhere changes the plan read; a verify still does not.
|
|
var all = await db.Sequences.GetStampAsync(archive.Id, null, Ct);
|
|
Assert.True(await db.Sequences.RecordVerifiedAsync(ridge.Id, SequenceStatus.None, SequenceStatus.None, TestData.Now.AddDays(1), Ct));
|
|
Assert.Equal(all, await db.Sequences.GetStampAsync(archive.Id, null, Ct));
|
|
await PhotoAsync(db, ridge, 1);
|
|
Assert.NotEqual(all, await db.Sequences.GetStampAsync(archive.Id, null, Ct));
|
|
}
|
|
|
|
/// <summary>A photo indexed into a sequence, as an upload does: the frame, then the row's counts and frames version.</summary>
|
|
private async Task PhotoAsync(ChronosDatabase db, Sequence sequence, int index)
|
|
{
|
|
var frame = TestData.Frame(sequence.Id, index);
|
|
await db.Frames.BulkInsertAsync([frame with { RelativePath = $"{sequence.Folder}/originals/{frame.FileName}" }], Ct);
|
|
Assert.NotNull(await db.Sequences.RefreshStatsAsync(sequence.Id, Ct));
|
|
}
|
|
}
|
|
|
|
public sealed class SqliteSequenceStampTests(TestContext context) : SequenceStampTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.SqliteMemory;
|
|
}
|
|
|
|
[RequiresEnvironment(PgTestServer.Variable)]
|
|
public sealed class PostgresSequenceStampTests(TestContext context) : SequenceStampTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.Postgres;
|
|
}
|