diff --git a/fleetd/src/test/java/dev/ltms/fleet/msg/LeadMailboxTest.java b/fleetd/src/test/java/dev/ltms/fleet/msg/LeadMailboxTest.java index e0c36ae..44ae57c 100644 --- a/fleetd/src/test/java/dev/ltms/fleet/msg/LeadMailboxTest.java +++ b/fleetd/src/test/java/dev/ltms/fleet/msg/LeadMailboxTest.java @@ -19,6 +19,7 @@ import java.util.concurrent.atomic.AtomicLong; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -207,6 +208,31 @@ class LeadMailboxTest { } } + /** + * {@link LeadMailbox#inspect} opens a third channel after the mailbox's consume and publish + * channels. Limit this connection to three channels, then require a replacement channel after + * the successful inspect. If inspect leaves its probe open, the broker refuses that replacement. + */ + @Test + void inspectClosesItsSuccessfulProbeChannel() throws Exception { + var factory = LeadMailbox.connectionFactory(uri()); + factory.setRequestedChannelMax(3); + Connection connection = factory.newConnection(); + try (LeadMailbox mailbox = new LeadMailbox(connection, coordId("lead-inspect-probe-close"))) { + LeadChannel.MailboxState state = mailbox.inspect(mailbox.selfCoordId()); + assertTrue(state.exists(), "the owned mailbox must be found before checking the probe channel"); + + Channel replacement = connection.createChannel(); + assertNotNull(replacement, + "inspect must close its successful probe channel; the replacement channel was null"); + try { + assertTrue(replacement.isOpen(), "the replacement channel must be open after inspect returns"); + } finally { + replacement.close(); + } + } + } + /** * fleetd #440: {@code heldDurable()} must be derived from what {@link LeadMailbox#own} actually * did against the real broker — a durable queue declare plus a manual-ack consumer — not a