* 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
This commit is contained in:
Artem Bilan
2022-05-20 11:59:09 -04:00
parent 7262c5f6fd
commit 274b27270f
2 changed files with 11 additions and 8 deletions

View File

@@ -8,7 +8,7 @@
<beans:bean id="integrationHeaderChannelRegistry"
class="org.springframework.integration.channel.DefaultHeaderChannelRegistry">
<beans:constructor-arg value="1000"/>
<beans:constructor-arg value="100"/>
</beans:bean>
<channel id="output">

View File

@@ -17,6 +17,7 @@
package org.springframework.integration.config.xml;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import java.util.Date;
import java.util.Map;
@@ -96,7 +97,7 @@ public class ControlBusTests {
}
@Test
public void testControlHeaderChannelReaper() throws InterruptedException {
public void testControlHeaderChannelReaper() {
MessagingTemplate messagingTemplate = new MessagingTemplate();
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
Message<?> result = this.output.receive(0);
@@ -108,13 +109,15 @@ public class ControlBusTests {
result = this.output.receive(0);
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo(1);
// Let the registry to reap old channels
Thread.sleep(1000);
// Let the registry reap old channels
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.runReaper()");
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
result = this.output.receive(0);
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo(0);
await()
.until(() -> {
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
Message<?> sizeMessage = this.output.receive(0);
assertThat(sizeMessage).isNotNull();
return sizeMessage.getPayload();
}, payload -> payload.equals(0));
}
@Test