Skip to content

Commit 0565930

Browse files
committed
Fix race condition in TcpOutGateTests.testAsync
The `ChannelInterceptor.postSend()` may be called when `MessageChannel.receive()` has already done its job polling from the queue where message appears in the `MessageChannel.doSend()` * Use `ChannelInterceptor.preSend()` contract instead to obtaine info about the current thread
1 parent a1f57e4 commit 0565930

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpOutboundGatewayTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -335,7 +335,7 @@ private AbstractClientConnectionFactory buildCF(final int port) {
335335

336336
/**
337337
* Sends 2 concurrent messages on a shared connection. The GW single threads
338-
* these requests. The first will timeout; the second should receive its
338+
* these requests. The first will time out; the second should receive its
339339
* own response, not that for the first.
340340
* @throws Exception
341341
*/
@@ -415,7 +415,7 @@ private void testGoodNetGWTimeoutGuts(AbstractClientConnectionFactory ccf,
415415
}
416416
// wait until the server side has processed both requests
417417
assertThat(serverLatch.await(30, TimeUnit.SECONDS)).isTrue();
418-
List<String> replies = new ArrayList<String>();
418+
List<String> replies = new ArrayList<>();
419419
int timeouts = 0;
420420
for (int i = 0; i < 2; i++) {
421421
try {
@@ -433,7 +433,6 @@ private void testGoodNetGWTimeoutGuts(AbstractClientConnectionFactory ccf,
433433
assertThat(e.getCause()).isInstanceOf(MessageTimeoutException.class);
434434
}
435435
timeouts++;
436-
continue;
437436
}
438437
}
439438
assertThat(timeouts).as("Expected exactly one ExecutionException").isEqualTo(1);
@@ -969,8 +968,9 @@ private void testAsync(boolean singleUse) throws Exception {
969968
replyChannel.addInterceptor(new ChannelInterceptor() {
970969

971970
@Override
972-
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
971+
public Message<?> preSend(Message<?> message, MessageChannel channel) {
973972
thread.set(Thread.currentThread());
973+
return message;
974974
}
975975

976976
});

0 commit comments

Comments
 (0)