From 0d1e2825e5e77c7f3a31c948ecb21a5c74d6fc37 Mon Sep 17 00:00:00 2001 From: Niek Otten Date: Mon, 20 Jul 2026 10:45:11 +0200 Subject: [PATCH] test(domain): timeout worker no-ops on an already-resolved registration (refs #102) RED: if the citizen withdrew while parked at WachtOpDocumenten, the RegistratieVerlopen job finds a terminal (INGETROKKEN) aggregate; the worker must no-op and let the job complete, not throw into a redelivery loop. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../ExpireRegistrationWorkerTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/services/domain/Big.Tests/ExpireRegistrationWorkerTests.cs b/services/domain/Big.Tests/ExpireRegistrationWorkerTests.cs index 612139f..dafc963 100644 --- a/services/domain/Big.Tests/ExpireRegistrationWorkerTests.cs +++ b/services/domain/Big.Tests/ExpireRegistrationWorkerTests.cs @@ -48,6 +48,25 @@ public class ExpireRegistrationWorkerTests Assert.Equal(RegistrationStatus.Verlopen, (await store.GetAsync(registration.Id))!.Status); } + [Fact] + public async Task An_already_resolved_registration_is_left_alone_and_the_job_completes() + { + // Race with S-11: the citizen withdrew while parked at WachtOpDocumenten, so the aggregate is + // already terminal (INGETROKKEN) when the timer's job arrives. Expiring it would violate the + // aggregate's invariant; the worker must instead no-op (and let the job complete), not throw + // into a redelivery loop. + var store = new FakeRegistrationStore(); + var registration = Submitted(); + registration.Withdraw(); + store.Seed(registration); + + await new ExpireRegistrationWorker(store).HandleAsync( + new RegistratieVerlopenJob("job-7", registration.Id)); + + Assert.Equal(0, store.SaveCount); + Assert.Equal(RegistrationStatus.Ingetrokken, (await store.GetAsync(registration.Id))!.Status); + } + [Fact] public async Task An_unknown_registration_throws_so_the_job_is_redelivered() {