Skip to content

Commit fed5324

Browse files
artembilanspring-builds
authored andcommitted
Fix MQTT event race condition in the Mqttv5BackToBackTests
The `MqttMessageDeliveredEvent` is published in async manner from the MQTT client. The message could be already consumed and verified, but `MqttMessageDeliveredEvent` is still not there. * Fix `Mqttv5BackToBackTests.testSimpleMqttv5Interaction()` with an `await().untilAsserted()` polling for the `MqttMessageDeliveredEvent` to appear in the list we want to verify. (cherry picked from commit fbb5b71)
1 parent 9efb841 commit fed5324

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/Mqttv5BackToBackTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
5353

5454
import static org.assertj.core.api.Assertions.assertThat;
55+
import static org.awaitility.Awaitility.await;
5556

5657
/**
5758
* @author Gary Russell
@@ -116,10 +117,11 @@ public void testSimpleMqttv5Interaction() {
116117
.get(IntegrationMessageHeaderAccessor.ACKNOWLEDGMENT_CALLBACK, SimpleAcknowledgment.class)
117118
.acknowledge();
118119

120+
await().untilAsserted(() ->
121+
assertThat(this.config.events).hasAtLeastOneElementOfType(MqttMessageDeliveredEvent.class));
122+
119123
assertThat(this.config.events)
120-
.isNotEmpty()
121124
.hasAtLeastOneElementOfType(MqttMessageSentEvent.class)
122-
.hasAtLeastOneElementOfType(MqttMessageDeliveredEvent.class)
123125
.hasAtLeastOneElementOfType(MqttSubscribedEvent.class);
124126

125127
this.mqttv5MessageDrivenChannelAdapter.addTopic("anotherTopic");

0 commit comments

Comments
 (0)