Skip to content

Commit

Permalink
Fix flaky tests (#5943)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ikhoon authored Oct 18, 2024
1 parent 8a6ae51 commit 411b6ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ public void onEviction(DnsQuestion question, @Nullable List<DnsRecord> records,
dnsCache.cache(query0, ImmutableList.of(record0));
// Exceeds the maximum size. The old cache, query0, should be removed.
dnsCache.cache(query1, ImmutableList.of(record1));

// Perform a get operation to trigger the eviction.
dnsCache.get(query0);
dnsCache.get(query1);
await().untilTrue(evicted);
assertThat(removed).isFalse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ protected HttpData filter(HttpData obj) {
.hasCauseInstanceOf(CancelledSubscriptionException.class);

final List<ByteBuf> bufs = ImmutableList.copyOf(data.values());

for (ByteBuf buf : bufs) {
assertThat(buf.refCnt()).isZero();
}
await().untilAsserted(() -> {
for (ByteBuf buf : bufs) {
assertThat(buf.refCnt()).isZero();
}
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ void shouldWaitForDisconnectByClientSideFirst() throws IOException {
assertThat(in.readLine()).isEmpty();
assertThat(in.readLine()).isEqualToIgnoringCase("OK");

assertThat(server.server().numConnections()).isEqualTo(1);
await().untilAsserted(() -> {
assertThat(server.server().numConnections()).isEqualTo(1);
});

socket.close();
assertThatThrownBy(
Expand Down

0 comments on commit 411b6ae

Please sign in to comment.