diff --git a/fleetd/src/test/java/dev/ltms/fleet/msg/LeadCoordLoopTest.java b/fleetd/src/test/java/dev/ltms/fleet/msg/LeadCoordLoopTest.java index dc35d24..2f626b8 100644 --- a/fleetd/src/test/java/dev/ltms/fleet/msg/LeadCoordLoopTest.java +++ b/fleetd/src/test/java/dev/ltms/fleet/msg/LeadCoordLoopTest.java @@ -68,6 +68,26 @@ class LeadCoordLoopTest { assertEquals(List.of("m1", "m1"), channel.acked(), "the redelivery still needs a fresh broker ack"); } + @Test + void aRedeliveryIsAckedEvenWhileTheLeadIsMidTurn() { + var channel = new FakeLeadChannel(SELF).hold(new LeadMessage("m1", PEER, SELF, "recover me")); + var herdr = new FakeHerdr().agentStatus("idle"); + var loop = loop(channel, herdr, Map.of(LEAD_TERM, SELF)); + + loop.tick(); + channel.hold(new LeadMessage("m1", PEER, SELF, "recover me")); + herdr.agentStatus("working"); + loop.tick(); + + assertEquals(1, prompts(herdr).size(), "the pane is still written exactly once"); + assertEquals(List.of("m1", "m1"), channel.acked(), + "a message already written to the pane must be acked even mid-turn: the mid-turn " + + "gate exists to protect the pane, and this message needs no pane. Gating the ack " + + "on it leaves the message held on a lead that is busy most of the time, and every " + + "recovery redelivers it again — which is the loop this fix exists to stop"); + assertTrue(channel.peek().isEmpty(), "so it is no longer held"); + } + @Test void leavesTheMessageUnackedWhenTheLeadIsMidTurn() { var channel = new FakeLeadChannel(SELF).hold(new LeadMessage("m1", PEER, SELF, "hello"));