merge: deterministic sync tests and a current-log download that survives new lines

This commit is contained in:
Claude committed 2026-10-06 22:22:47 +00:00
commit 01f301f970
5 files changed
+175 -27

No files matched your search

@@ -22,6 +22,9 @@ public sealed class SyncServerTests(TestContext context)
private const string Window41 = """{"exposure":{"deflickerWindow":{"isAuto":false,"manual":41}}}""";
private const string Window33 = """{"exposure":{"deflickerWindow":{"isAuto":false,"manual":33}}}""";
/// <summary>How long any wait may take on a loaded runner; every wait ends as soon as what it waits for happened.</summary>
private static readonly TimeSpan Deadline = TimeSpan.FromSeconds(60);
[Test]
public async Task ASequenceUploadedFromOnePcDownloadsIdenticallyOnAnother()
{
@@ -147,12 +150,16 @@ public sealed class SyncServerTests(TestContext context)
var hub = server.Services.GetRequiredService<EventHub>();
await UntilAsync(() => Task.FromResult(agent.Snapshot is not null && hub.SubscriberCount > 0), "the agent's first comparison and event socket");
// Someone edits the project on the server (web or another PC).
// Someone edits the project on the server (web or another PC). The comparison its event starts writes the
// settings on this PC before the link that records the agreement: wait for the comparison, not for the settings.
var compared = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
studio.Sync.Changed += _ => compared.TrySetResult();
using (var patch = await http.PatchAsJsonAsync($"/api/v1/sequences/{remoteId}",
new UpdateSequenceRequest(null, null, null, null, Window33, null), ProtocolJson.Default.UpdateSequenceRequest))
await patch.ExpectAsync(HttpStatusCode.OK);
await UntilAsync(async () => ProjectSettings.FromJson((await studio.Db.Sequences.GetAsync(local.Id))!.SettingsJson ?? "{}").Exposure.DeflickerWindow.Manual == 33,
await SignalAsync(compared.Task, "the comparison of the edit");
Assert.Equal(33, ProjectSettings.FromJson((await studio.Db.Sequences.GetAsync(local.Id))!.SettingsJson ?? "{}").Exposure.DeflickerWindow.Manual,
"the edit reached this PC");
Assert.Equal(SyncStatus.InSync, (await studio.EntryAsync("Harbour sunset")).Status);
}
@@ -247,11 +254,23 @@ public sealed class SyncServerTests(TestContext context)
private async Task UntilAsync(Func<Task<bool>> condition, string what)
{
var until = DateTime.UtcNow.AddSeconds(60);
var until = DateTime.UtcNow + Deadline;
while (!await condition())
{
if (DateTime.UtcNow > until) Assert.Fail("Timed out waiting for " + what);
await Task.Delay(50, context.Cancellation);
}
}
private async Task SignalAsync(Task signal, string what)
{
try
{
await signal.WaitAsync(Deadline, context.Cancellation);
}
catch (TimeoutException)
{
Assert.Fail("Timed out waiting for " + what);
}
}
}