Skip to content

Commit 95b7592

Browse files
committed
Improve flaky test
It fails sometimes on CI. Use concurrent collections, make test failure more readable.
1 parent 80eeaac commit 95b7592

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/test/java/com/rabbitmq/stream/impl/ClientTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ void publishConfirmWithSeveralPublisherIds() throws Exception {
180180
}
181181
};
182182

183-
Map<Byte, Set<Long>> confirmed = new HashMap<>();
184-
Map<Byte, Set<Long>> publishingSequences = new HashMap<>();
183+
Map<Byte, Set<Long>> confirmed = new ConcurrentHashMap<>();
184+
Map<Byte, Set<Long>> publishingSequences = new ConcurrentHashMap<>();
185185
AtomicInteger totalMessageCount = new AtomicInteger(0);
186186
outboundMessagesSpec
187187
.keySet()
@@ -232,23 +232,23 @@ void publishConfirmWithSeveralPublisherIds() throws Exception {
232232
});
233233
})
234234
.collect(Collectors.toList())
235-
.forEach(thread -> thread.start());
235+
.forEach(Thread::start);
236236

237237
assertThat(confirmLatch.await(10, SECONDS)).isTrue();
238-
outboundMessagesSpec
239-
.entrySet()
240-
.forEach(
241-
entry -> {
242-
byte publisherId = entry.getKey();
243-
int expectedMessageCount = entry.getValue();
244-
Set<Long> sequences = publishingSequences.get(publisherId);
245-
assertThat(confirmed.get(publisherId))
246-
.hasSize(expectedMessageCount)
247-
.hasSameSizeAs(sequences);
248-
confirmed
249-
.get(publisherId)
250-
.forEach(publishingId -> assertThat(sequences.contains(publishingId)).isTrue());
251-
});
238+
outboundMessagesSpec.forEach(
239+
(key, value) -> {
240+
byte publisherId = key;
241+
int expectedMessageCount = value;
242+
Set<Long> sequences = publishingSequences.get(publisherId);
243+
Set<Long> confirmedPublishingIds = confirmed.get(publisherId);
244+
// Not using collection assertions because they dump the whole content
245+
// This is unreadable for large collections
246+
assertThat(sequences.size()).isEqualTo(expectedMessageCount);
247+
assertThat(confirmedPublishingIds.size()).isEqualTo(expectedMessageCount);
248+
249+
confirmedPublishingIds.forEach(
250+
publishingId -> assertThat(sequences.contains(publishingId)).isTrue());
251+
});
252252
}
253253

254254
void publishConsumeComplexMessage(

0 commit comments

Comments
 (0)