From c7ed1e6e36e634c40f3837a7099d1c0506d8a622 Mon Sep 17 00:00:00 2001 From: Dmitrii Shmatko Date: Fri, 8 Sep 2023 18:54:47 +0400 Subject: [PATCH] Fix test errors --- .../teku/storage/server/pruner/BlockPrunerTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/storage/src/test/java/tech/pegasys/teku/storage/server/pruner/BlockPrunerTest.java b/storage/src/test/java/tech/pegasys/teku/storage/server/pruner/BlockPrunerTest.java index 21959e1e5f2..a9a2eb4137f 100644 --- a/storage/src/test/java/tech/pegasys/teku/storage/server/pruner/BlockPrunerTest.java +++ b/storage/src/test/java/tech/pegasys/teku/storage/server/pruner/BlockPrunerTest.java @@ -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; @@ -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( @@ -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 @@ -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 @@ -88,6 +94,7 @@ 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 @@ -95,6 +102,7 @@ void shouldNotPruneWhenFinalizedCheckpointNotSet() { when(database.getFinalizedCheckpoint()).thenReturn(Optional.empty()); triggerNextPruning(); verify(database, never()).pruneFinalizedBlocks(any(), eq(PRUNE_SLOTS)); + verify(pruningActiveLabelledGauge).set(eq(0.), any()); } @Test @@ -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 @@ -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 @@ -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() {