fix(events): card reports cannot crowd the event queues or hold an import
The server publishes one account's card progress at most once a second (sooner reports are taken and dropped) and at most 120 card events of an account a minute (429 rate_limited beyond), so an upload-only account can no longer push job and sequence events out of every client's queue. On the client, the end of a card import waits at most two seconds for its reports to reach the server, then cancels whatever is still on its way, so a cancelled import or one that lost its server ends at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
5 files changed
+146
-12
No files matched your search
@@ -172,8 +172,30 @@ public sealed class ServerImportSinkTests(TestContext context)
|
||||
|
||||
// The start was on its way; progress 10 waited and was replaced by 30 (20 came within the second), then by the end.
|
||||
Assert.SequenceEqual([(CardImportStates.Started, 0), (CardImportStates.Finished, 30)], server.Cards.Select(r => (r.State, r.Done)));
|
||||
// Nothing follows the end, not even progress a second later.
|
||||
time.Advance(TimeSpan.FromSeconds(1));
|
||||
reporter.Report(Progress(40));
|
||||
Assert.Count(2, server.Cards);
|
||||
await reporter.FinishedAsync(null).WaitAsync(TimeSpan.FromSeconds(10));
|
||||
Assert.Equal(2, server.CardAttempts);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnImportOverDoesNotWaitForAServerThatDoesNotAnswer()
|
||||
{
|
||||
var server = new FakeUploadServer(chunkSize: 4096) { CardGate = new TaskCompletionSource().Task };
|
||||
using var client = new TitanoClient(new Uri("https://nas.local:8443/"), new CertificatePinning([]), "tests", server) { Token = "t" };
|
||||
var reporter = new CardImportReporter(client, Guid.CreateVersion7(), "EOS R5 · card A", 100);
|
||||
|
||||
reporter.Started();
|
||||
await server.CardArrived.Task.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
var clock = System.Diagnostics.Stopwatch.StartNew();
|
||||
await reporter.FinishedAsync(null).WaitAsync(TimeSpan.FromSeconds(8));
|
||||
|
||||
// The start hangs (each report would wait 10 s): the end gives both up after two seconds.
|
||||
Assert.True(clock.Elapsed < TimeSpan.FromSeconds(6), $"finished after {clock.Elapsed}");
|
||||
Assert.Empty(server.Cards);
|
||||
for (var i = 0; i < 25 && server.CardAttempts < 2; i++) await Task.Delay(20);
|
||||
Assert.Equal(1, server.CardAttempts, "the end was never sent once given up");
|
||||
}
|
||||
|
||||
private static ImportProgress Progress(int done) => new(done, 100, done * 10L, 1000, done, 0, 0, null);
|
||||
|
||||
Reference in new issue
Block a user