From 9f3f5df08c25b840abeb6082468d5cebf2b01621 Mon Sep 17 00:00:00 2001 From: Mehdi AOUADI Date: Wed, 16 Oct 2024 11:47:50 +0200 Subject: [PATCH] make tests parametrized --- .../HistoricalBatchFetcherTest.java | 3 +- .../chainstorage/StorageServiceTest.java | 29 +++++++------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/historical/HistoricalBatchFetcherTest.java b/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/historical/HistoricalBatchFetcherTest.java index 7fe92edf82a..0b81c205023 100644 --- a/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/historical/HistoricalBatchFetcherTest.java +++ b/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/historical/HistoricalBatchFetcherTest.java @@ -55,6 +55,7 @@ import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.client.EarliestAvailableBlockSlot; import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.storage.server.StateStorageMode; import tech.pegasys.teku.storage.storageSystem.InMemoryStorageSystemBuilder; import tech.pegasys.teku.storage.storageSystem.StorageSystem; @@ -290,7 +291,7 @@ public void run_requestBatchWithSkippedSlots() { } @ParameterizedTest - @ValueSource(booleans = {true, false}) + @ValueSource(classes = {StateStorageMode.class, false}) public void run_requestBatchForRangeOfEmptyBlocks(final boolean blobSidecarsRequired) { if (blobSidecarsRequired) { when(blobSidecarManager.isAvailabilityRequiredAtSlot(any())).thenReturn(true); diff --git a/services/chainstorage/src/test/java/tech/pegasys/teku/services/chainstorage/StorageServiceTest.java b/services/chainstorage/src/test/java/tech/pegasys/teku/services/chainstorage/StorageServiceTest.java index eddd7ca6f65..845f63b5245 100644 --- a/services/chainstorage/src/test/java/tech/pegasys/teku/services/chainstorage/StorageServiceTest.java +++ b/services/chainstorage/src/test/java/tech/pegasys/teku/services/chainstorage/StorageServiceTest.java @@ -26,6 +26,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.ValueSource; import tech.pegasys.teku.ethereum.execution.types.Eth1Address; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.async.StubAsyncRunner; @@ -104,21 +107,10 @@ void shouldSetupStatePrunerWhenArchiveModeAndRetentionSlotsEnabled() { .isEqualTo(StorageConfiguration.DEFAULT_STATE_PRUNING_INTERVAL); } - @Test - void shouldSetupStatePrunerWhenPruneMode() { - when(storageConfiguration.getDataStorageMode()).thenReturn(StateStorageMode.PRUNE); - final SafeFuture future = storageService.doStart(); - final Optional maybeStatePruner = storageService.getStatePruner(); - assertThat(future).isCompleted(); - assertThat(maybeStatePruner).isPresent(); - final StatePruner statePruner = maybeStatePruner.get(); - assertThat(statePruner.isRunning()).isTrue(); - assertThat(statePruner.getPruneInterval()).isEqualTo(StorageService.STATE_PRUNING_INTERVAL); - } - - @Test - void shouldSetupStatePrunerWhenMinimalMode() { - when(storageConfiguration.getDataStorageMode()).thenReturn(StateStorageMode.MINIMAL); + @ParameterizedTest + @EnumSource(value = StateStorageMode.class, names = {"PRUNE", "MINIMAL"}) + void shouldSetupStatePrunerWhenPruneMode(final StateStorageMode stateStorageMode) { + when(storageConfiguration.getDataStorageMode()).thenReturn(stateStorageMode); final SafeFuture future = storageService.doStart(); final Optional maybeStatePruner = storageService.getStatePruner(); assertThat(future).isCompleted(); @@ -128,9 +120,10 @@ void shouldSetupStatePrunerWhenMinimalMode() { assertThat(statePruner.getPruneInterval()).isEqualTo(StorageService.STATE_PRUNING_INTERVAL); } - @Test - void shouldSetupStatePrunerWithCustomInterval() { - when(storageConfiguration.getDataStorageMode()).thenReturn(StateStorageMode.MINIMAL); + @ParameterizedTest + @EnumSource(value = StateStorageMode.class, names = {"PRUNE", "MINIMAL"}) + void shouldSetupStatePrunerWithCustomInterval(final StateStorageMode stateStorageMode) { + when(storageConfiguration.getDataStorageMode()).thenReturn(stateStorageMode); final Duration customPruningInterval = Duration.ofSeconds(8); when(storageConfiguration.getStatePruningInterval()).thenReturn(customPruningInterval); final SafeFuture future = storageService.doStart();