Skip to content

Commit 274b272

Browse files
committed
* Improve time-sensitive ControlBusTests.testControlHeaderChannelReaper()
The `Thread.sleep(1000);` doesn't give a good async barrier to rely on in the subsequent verification logic. Use `await().until()` instead for several attempts until a condition is fulfilled ot 10 seconds timeout is exhausted. Also decrease `reapDelay` to `500` for better test suite performance
1 parent 7262c5f commit 274b272

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusTests-context.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<beans:bean id="integrationHeaderChannelRegistry"
1010
class="org.springframework.integration.channel.DefaultHeaderChannelRegistry">
11-
<beans:constructor-arg value="1000"/>
11+
<beans:constructor-arg value="100"/>
1212
</beans:bean>
1313

1414
<channel id="output">

spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusTests.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.integration.config.xml;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.awaitility.Awaitility.await;
2021

2122
import java.util.Date;
2223
import java.util.Map;
@@ -96,7 +97,7 @@ public void testLifecycleMethods() {
9697
}
9798

9899
@Test
99-
public void testControlHeaderChannelReaper() throws InterruptedException {
100+
public void testControlHeaderChannelReaper() {
100101
MessagingTemplate messagingTemplate = new MessagingTemplate();
101102
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
102103
Message<?> result = this.output.receive(0);
@@ -108,13 +109,15 @@ public void testControlHeaderChannelReaper() throws InterruptedException {
108109
result = this.output.receive(0);
109110
assertThat(result).isNotNull();
110111
assertThat(result.getPayload()).isEqualTo(1);
111-
// Let the registry to reap old channels
112-
Thread.sleep(1000);
112+
// Let the registry reap old channels
113113
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.runReaper()");
114-
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
115-
result = this.output.receive(0);
116-
assertThat(result).isNotNull();
117-
assertThat(result.getPayload()).isEqualTo(0);
114+
await()
115+
.until(() -> {
116+
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
117+
Message<?> sizeMessage = this.output.receive(0);
118+
assertThat(sizeMessage).isNotNull();
119+
return sizeMessage.getPayload();
120+
}, payload -> payload.equals(0));
118121
}
119122

120123
@Test

0 commit comments

Comments
 (0)