Skip to content

Commit 411b6ae

Browse files
authored
Fix flaky tests (#5943)
Motivation: Three tests often fail in CI builds. - #5942 - #5724 - #4960 The cause of the failures seems to be a timing issue. Modifications: - Wrap assertion with `await().untilAsserted()` - Perform get operations to evict the old caches. Result: - Fixes #5942 - Fixes #5724 - Fixes #4960
1 parent 8a6ae51 commit 411b6ae

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

core/src/test/java/com/linecorp/armeria/client/DefaultDnsCacheTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ public void onEviction(DnsQuestion question, @Nullable List<DnsRecord> records,
290290
dnsCache.cache(query0, ImmutableList.of(record0));
291291
// Exceeds the maximum size. The old cache, query0, should be removed.
292292
dnsCache.cache(query1, ImmutableList.of(record1));
293+
294+
// Perform a get operation to trigger the eviction.
295+
dnsCache.get(query0);
296+
dnsCache.get(query1);
293297
await().untilTrue(evicted);
294298
assertThat(removed).isFalse();
295299
}

core/src/test/java/com/linecorp/armeria/common/stream/StreamMessageCollectingTest.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ protected HttpData filter(HttpData obj) {
207207
.hasCauseInstanceOf(CancelledSubscriptionException.class);
208208

209209
final List<ByteBuf> bufs = ImmutableList.copyOf(data.values());
210-
211-
for (ByteBuf buf : bufs) {
212-
assertThat(buf.refCnt()).isZero();
213-
}
210+
await().untilAsserted(() -> {
211+
for (ByteBuf buf : bufs) {
212+
assertThat(buf.refCnt()).isZero();
213+
}
214+
});
214215
}
215216

216217
@Test

core/src/test/java/com/linecorp/armeria/server/Http1ServerDelayedCloseConnectionTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ void shouldWaitForDisconnectByClientSideFirst() throws IOException {
109109
assertThat(in.readLine()).isEmpty();
110110
assertThat(in.readLine()).isEqualToIgnoringCase("OK");
111111

112-
assertThat(server.server().numConnections()).isEqualTo(1);
112+
await().untilAsserted(() -> {
113+
assertThat(server.server().numConnections()).isEqualTo(1);
114+
});
113115

114116
socket.close();
115117
assertThatThrownBy(

0 commit comments

Comments
 (0)