Skip to content

Commit

Permalink
fix: add retention-based eviction to memory-based cache metrics test
Browse files Browse the repository at this point in the history
Similar to disk-based test, as deletion is not happening consistently leading to flakiness, this commit includes time-based retention to force deletion and validate metrics.
  • Loading branch information
jeqo committed Aug 8, 2024
1 parent 615a0af commit 01deb75
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void timeBasedEviction() throws IOException, StorageBackendException, Interrupte
void sizeBasedEviction() throws IOException, StorageBackendException {
cache.configure(Map.of(
"size", "18",
"retention.ms", "-1"
"retention.ms", String.valueOf(Duration.ofSeconds(10).toMillis())
));
assertThat(cache.cache.asMap()).isEmpty();

Expand Down Expand Up @@ -253,13 +253,14 @@ void sizeBasedEviction() throws IOException, StorageBackendException {
assertThat(timeIndex).hasBinaryContent(TIME_INDEX);
assertThat(cache.cache.asMap()).isNotEmpty();

// because of the retention ms, it may be deleting cached values 1, 2 or both.
await()
.atMost(Duration.ofSeconds(30)) // increase to reduce chance of flakiness
.atMost(Duration.ofSeconds(30))
.pollDelay(Duration.ofSeconds(2))
.pollInterval(Duration.ofMillis(10))
.until(() -> !mockingDetails(removalListener).getInvocations().isEmpty());

assertThat(cache.cache.asMap()).hasSize(1);
assertThat(cache.cache.asMap().size()).isLessThanOrEqualTo(1);
verify(removalListener).onRemoval(any(SegmentIndexKey.class), any(), eq(RemovalCause.SIZE));
}
}
Expand Down

0 comments on commit 01deb75

Please sign in to comment.