Skip to content

Commit

Permalink
Fix test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zilm13 committed Sep 8, 2023
1 parent dc5959f commit c7ed1e6
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -52,6 +54,8 @@ class BlockPrunerTest {
private final StubTimeProvider timeProvider = StubTimeProvider.withTimeInSeconds(1000);
private final StubAsyncRunner asyncRunner = new StubAsyncRunner(timeProvider);
private final Database database = mock(Database.class);
private final SettableLabelledGauge pruningActiveLabelledGauge =
mock(SettableLabelledGauge.class);

private final BlockPruner pruner =
new BlockPruner(
Expand All @@ -62,12 +66,13 @@ class BlockPrunerTest {
PRUNE_SLOTS,
"test",
mock(SettableLabelledGauge.class),
mock(SettableLabelledGauge.class));
pruningActiveLabelledGauge);

@BeforeEach
void setUp() {
epochsToKeep = spec.getNetworkingConfig().getMinEpochsForBlockRequests();
assertThat(pruner.start()).isCompleted();
when(database.pruneFinalizedBlocks(any(), anyInt())).thenReturn(UInt64.ZERO);
}

@Test
Expand All @@ -76,6 +81,7 @@ void shouldPruneWhenFirstStarted() {
.thenReturn(Optional.of(dataStructureUtil.randomCheckpoint(UInt64.valueOf(50))));
asyncRunner.executeDueActions();
verify(database).pruneFinalizedBlocks(any(), eq(PRUNE_SLOTS));
verify(pruningActiveLabelledGauge).set(eq(0.), any());
}

@Test
Expand All @@ -88,13 +94,15 @@ void shouldPruneAfterInterval() {
.thenReturn(Optional.of(dataStructureUtil.randomCheckpoint(UInt64.valueOf(52))));
triggerNextPruning();
verify(database).pruneFinalizedBlocks(any(), eq(PRUNE_SLOTS));
verify(pruningActiveLabelledGauge, times(2)).set(eq(0.), any());
}

@Test
void shouldNotPruneWhenFinalizedCheckpointNotSet() {
when(database.getFinalizedCheckpoint()).thenReturn(Optional.empty());
triggerNextPruning();
verify(database, never()).pruneFinalizedBlocks(any(), eq(PRUNE_SLOTS));
verify(pruningActiveLabelledGauge).set(eq(0.), any());
}

@Test
Expand All @@ -103,6 +111,7 @@ void shouldNotPruneWhenFinalizedCheckpointBelowEpochsToKeep() {
.thenReturn(Optional.of(dataStructureUtil.randomCheckpoint(epochsToKeep)));
triggerNextPruning();
verify(database, never()).pruneFinalizedBlocks(any(), eq(PRUNE_SLOTS));
verify(pruningActiveLabelledGauge).set(eq(0.), any());
}

@Test
Expand All @@ -115,6 +124,7 @@ void shouldPruneBlocksMoreThanEpochsToKeepBeforeFinalizedCheckpoint() {
// = 500 - 50 = 450, last slot to prune = 450 - 1 = 449.
final UInt64 lastSlotToPrune = UInt64.valueOf(449);
verify(database).pruneFinalizedBlocks(lastSlotToPrune, PRUNE_SLOTS);
verify(pruningActiveLabelledGauge).set(eq(0.), any());
}

@Test
Expand All @@ -126,6 +136,7 @@ void shouldPruneBlocksWhenFirstEpochIsPrunable() {
// Should prune all blocks in the first epoch (ie blocks 0 - 9)
final UInt64 lastSlotToPrune = UInt64.valueOf(SLOTS_PER_EPOCH - 1);
verify(database).pruneFinalizedBlocks(lastSlotToPrune, PRUNE_SLOTS);
verify(pruningActiveLabelledGauge).set(eq(0.), any());
}

private void triggerNextPruning() {
Expand Down

0 comments on commit c7ed1e6

Please sign in to comment.