diff --git a/tests/Titano.Server.Tests/Sync/SyncServerTests.cs b/tests/Titano.Server.Tests/Sync/SyncServerTests.cs
index c7d1c00b..daea9b86 100644
--- a/tests/Titano.Server.Tests/Sync/SyncServerTests.cs
+++ b/tests/Titano.Server.Tests/Sync/SyncServerTests.cs
@@ -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}}}""";
+ /// How long any wait may take on a loaded runner; every wait ends as soon as what it waits for happened.
+ 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();
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);
}
@@ -244,11 +251,23 @@ public sealed class SyncServerTests(TestContext context)
private async Task UntilAsync(Func> 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);
+ }
+ }
}