Skip to content

Commit 994df88

Browse files
committed
Fix race condition in the RabbitAmqpListenerTests
According to the `Collections.synchronizedList()` Javadocs, it has to be iterated with a `synchronized (list)`. Otherwise, there is no guarantee that memory barrier for list items is fulfilled.
1 parent 9c0c4e2 commit 994df88

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

spring-rabbitmq-client/src/test/java/org/springframework/amqp/rabbitmq/client/listener/RabbitAmqpListenerTests.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ void verifyAllDataIsConsumedFromQ1AndQ2() throws InterruptedException {
8989

9090
assertThat(this.config.consumeIsDone.await(10, TimeUnit.SECONDS)).isTrue();
9191

92-
assertThat(this.config.received).containsAll(testDataList);
92+
synchronized (this.config.received) {
93+
assertThat(this.config.received).containsAll(testDataList);
94+
}
9395

9496
assertThat(this.template.receive("dlq1")).succeedsWithin(10, TimeUnit.SECONDS);
9597
assertThat(this.template.receive("dlq1")).succeedsWithin(10, TimeUnit.SECONDS);
@@ -166,7 +168,7 @@ RabbitAmqpListenerContainerFactory rabbitAmqpListenerContainerFactory(AmqpConnec
166168
return new RabbitAmqpListenerContainerFactory(connectionFactory);
167169
}
168170

169-
List<String> received = Collections.synchronizedList(new ArrayList<>());
171+
final List<String> received = Collections.synchronizedList(new ArrayList<>());
170172

171173
CountDownLatch consumeIsDone = new CountDownLatch(10);
172174

0 commit comments

Comments
 (0)