Skip to content

Commit 7705793

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 bf097ca commit 7705793

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
@@ -27,6 +27,7 @@
2727
import static org.mockito.AdditionalMatchers.aryEq;
2828
import static org.mockito.ArgumentMatchers.any;
2929
import static org.mockito.ArgumentMatchers.anyInt;
30+
import static org.mockito.ArgumentMatchers.anyLong;
3031
import static org.mockito.ArgumentMatchers.anyString;
3132
import static org.mockito.ArgumentMatchers.isNull;
3233
import static org.mockito.BDDMockito.given;
@@ -1678,6 +1679,11 @@ public void testOrderlyShutDown() throws Exception {
16781679
ccf.setApplicationContext(ac);
16791680
PublisherCallbackChannel pcc = mock(PublisherCallbackChannel.class);
16801681
given(pcc.isOpen()).willReturn(true);
1682+
CountDownLatch asyncClosingLatch = new CountDownLatch(1);
1683+
willAnswer(invoc -> {
1684+
asyncClosingLatch.countDown();
1685+
return null;
1686+
}).given(pcc).waitForConfirmsOrDie(anyLong());
16811687
AtomicReference<ExecutorService> executor = new AtomicReference<>();
16821688
AtomicBoolean rejected = new AtomicBoolean(true);
16831689
CountDownLatch closeLatch = new CountDownLatch(1);
@@ -1699,12 +1705,10 @@ public void testOrderlyShutDown() throws Exception {
16991705
}).given(pcc).close();
17001706
Channel channel = ccf.createConnection().createChannel(false);
17011707
ExecutorService closeExec = Executors.newSingleThreadExecutor();
1702-
CountDownLatch asyncClosingLatch = new CountDownLatch(1);
17031708
closeExec.execute(() -> {
17041709
RabbitUtils.setPhysicalCloseRequired(channel, true);
17051710
try {
17061711
channel.close();
1707-
asyncClosingLatch.countDown();
17081712
}
17091713
catch (@SuppressWarnings("unused") IOException | TimeoutException e) {
17101714
// ignore

0 commit comments

Comments
 (0)