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 4ecdfb7
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -211,11 +212,11 @@ void timeBasedEviction() throws IOException, StorageBackendException, Interrupte
eq(RemovalCause.EXPIRED));
}

@Test
@RepeatedTest(10000)
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 +254,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 4ecdfb7

Please sign in to comment.