Skip to content

Commit f276af9

Browse files
committed
Fix another LockRequestHandlerAdviceTests race condition
There is no guarantee which message would reach the service first when we use `asyncConvertSendAndReceive()`. * Add `config.longProcessEnteredLatch` to wait before sending the second (fourth in our case) message until the long-running process against the first (third in our case) message has been started.
1 parent 41e2b87 commit f276af9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

spring-integration-core/src/test/java/org/springframework/integration/handler/advice/LockRequestHandlerAdviceTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ void verifyLockAroundHandler() throws ExecutionException, InterruptedException,
9090
Future<Object> test3 =
9191
messagingTemplate.asyncConvertSendAndReceive(this.inputChannel, "longer_process", messagePostProcessor);
9292

93+
// Ensure that we have entered a long process before sending new message.
94+
// Otherwise, there is no guarantee which message would reach the service first.
95+
assertThat(this.config.longProcessEnteredLatch.await(10, TimeUnit.SECONDS)).isTrue();
96+
9397
Future<Object> test4 =
9498
messagingTemplate.asyncConvertSendAndReceive(this.inputChannel, "test4", messagePostProcessor);
9599

@@ -130,6 +134,8 @@ LockRequestHandlerAdvice lockRequestHandlerAdvice(LockRegistry lockRegistry, Que
130134

131135
AtomicInteger counter = new AtomicInteger();
132136

137+
CountDownLatch longProcessEnteredLatch = new CountDownLatch(1);
138+
133139
CountDownLatch longProcessLatch = new CountDownLatch(1);
134140

135141
@ServiceActivator(inputChannel = "inputChannel", adviceChain = "lockRequestHandlerAdvice")
@@ -138,6 +144,7 @@ String handleWithDelay(String payload) throws InterruptedException {
138144
if ("longer_process".equals(payload)) {
139145
// Hard to achieve blocking expectations just with timeouts.
140146
// So, wait for count-down-latch to be fulfilled.
147+
longProcessEnteredLatch.countDown();
141148
longProcessLatch.await(10, TimeUnit.SECONDS);
142149
}
143150
else {

0 commit comments

Comments
 (0)