Skip to content

Commit

Permalink
* Improve time-sensitive `ControlBusTests.testControlHeaderChannelRea…
Browse files Browse the repository at this point in the history
…per()`

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
  • Loading branch information
artembilan committed May 20, 2022
1 parent 7262c5f commit 274b272
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,7 +97,7 @@ public void testLifecycleMethods() {
}

@Test
public void testControlHeaderChannelReaper() throws InterruptedException {
public void testControlHeaderChannelReaper() {
MessagingTemplate messagingTemplate = new MessagingTemplate();
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
Message<?> result = this.output.receive(0);
Expand All @@ -108,13 +109,15 @@ public void testControlHeaderChannelReaper() throws InterruptedException {
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
Expand Down

0 comments on commit 274b272

Please sign in to comment.