Skip to content

Commit 3648396

Browse files
garyrussellartembilan
authored andcommitted
GH-994: Improve test
See #994 Move the `closingLatch.countDown()` to `waitForConfirmsOrDie()` so we are sure the in-flight async close is running. Previously, there was a race because the latch was counted down just before the close was issued on the async thread.
1 parent 1098d27 commit 3648396

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.mockito.AdditionalMatchers.aryEq;
2222
import static org.mockito.ArgumentMatchers.any;
2323
import static org.mockito.ArgumentMatchers.anyInt;
24+
import static org.mockito.ArgumentMatchers.anyLong;
2425
import static org.mockito.ArgumentMatchers.anyString;
2526
import static org.mockito.ArgumentMatchers.isNull;
2627
import static org.mockito.BDDMockito.given;
@@ -1627,6 +1628,11 @@ public void testOrderlyShutDown() throws Exception {
16271628
ccf.setApplicationContext(ac);
16281629
PublisherCallbackChannel pcc = mock(PublisherCallbackChannel.class);
16291630
given(pcc.isOpen()).willReturn(true);
1631+
CountDownLatch asyncClosingLatch = new CountDownLatch(1);
1632+
willAnswer(invoc -> {
1633+
asyncClosingLatch.countDown();
1634+
return null;
1635+
}).given(pcc).waitForConfirmsOrDie(anyLong());
16301636
AtomicReference<ExecutorService> executor = new AtomicReference<>();
16311637
AtomicBoolean rejected = new AtomicBoolean(true);
16321638
CountDownLatch closeLatch = new CountDownLatch(1);
@@ -1648,12 +1654,10 @@ public void testOrderlyShutDown() throws Exception {
16481654
}).given(pcc).close();
16491655
Channel channel = ccf.createConnection().createChannel(false);
16501656
ExecutorService closeExec = Executors.newSingleThreadExecutor();
1651-
CountDownLatch asyncClosingLatch = new CountDownLatch(1);
16521657
closeExec.execute(() -> {
16531658
RabbitUtils.setPhysicalCloseRequired(channel, true);
16541659
try {
16551660
channel.close();
1656-
asyncClosingLatch.countDown();
16571661
}
16581662
catch (@SuppressWarnings("unused") IOException | TimeoutException e) {
16591663
// ignore

0 commit comments

Comments
 (0)