From 63ca2ab5620880fc2c2eda39b86bafb3a6f1d2ab Mon Sep 17 00:00:00 2001 From: etiennehomer Date: Wed, 29 Jan 2025 14:06:57 +0100 Subject: [PATCH] Fix: make repository tests independant (#94) Using a different db for each method with the cheap technique like other places. Reduce logging verbosity by not logging liquibase updates at all, they are too noisy at the begining of each test Signed-off-by: Etienne Homer --- .../src/test/resources/application-default.yml | 1 + .../store/server/NetworkStoreRepositoryTest.java | 10 ++++++++++ .../network/store/server/V211LimitsMigrationTest.java | 8 ++++++++ .../src/test/resources/application-default.yml | 7 +++++++ 4 files changed, 26 insertions(+) diff --git a/network-store-integration-test/src/test/resources/application-default.yml b/network-store-integration-test/src/test/resources/application-default.yml index bcb106a6..d45707a7 100644 --- a/network-store-integration-test/src/test/resources/application-default.yml +++ b/network-store-integration-test/src/test/resources/application-default.yml @@ -14,3 +14,4 @@ logging: # suppress db config startup logs, they appear hundred of times # because we don't reuse spring context to drop the in memory db com.zaxxer.hikari.HikariConfig: INFO + liquibase: ERROR # too verbose to dump liquibase operations at the begining of each test diff --git a/network-store-server/src/test/java/com/powsybl/network/store/server/NetworkStoreRepositoryTest.java b/network-store-server/src/test/java/com/powsybl/network/store/server/NetworkStoreRepositoryTest.java index 1f95c837..fd27db2a 100644 --- a/network-store-server/src/test/java/com/powsybl/network/store/server/NetworkStoreRepositoryTest.java +++ b/network-store-server/src/test/java/com/powsybl/network/store/server/NetworkStoreRepositoryTest.java @@ -14,12 +14,16 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; import java.util.*; import static org.junit.jupiter.api.Assertions.*; @SpringBootTest +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) class NetworkStoreRepositoryTest { private static final UUID NETWORK_UUID = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); @@ -27,6 +31,12 @@ class NetworkStoreRepositoryTest { @Autowired private NetworkStoreRepository networkStoreRepository; + @DynamicPropertySource + static void makeTestDbSuffix(DynamicPropertyRegistry registry) { + UUID uuid = UUID.randomUUID(); + registry.add("testDbSuffix", () -> uuid); + } + @Test void insertTemporaryLimitsInLinesTest() { diff --git a/network-store-server/src/test/java/com/powsybl/network/store/server/V211LimitsMigrationTest.java b/network-store-server/src/test/java/com/powsybl/network/store/server/V211LimitsMigrationTest.java index 4d8e3376..6b03d232 100644 --- a/network-store-server/src/test/java/com/powsybl/network/store/server/V211LimitsMigrationTest.java +++ b/network-store-server/src/test/java/com/powsybl/network/store/server/V211LimitsMigrationTest.java @@ -20,6 +20,8 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @@ -60,6 +62,12 @@ class V211LimitsMigrationTest { @Autowired private MockMvc mvc; + @DynamicPropertySource + static void makeTestDbSuffix(DynamicPropertyRegistry registry) { + UUID uuid = UUID.randomUUID(); + registry.add("testDbSuffix", () -> uuid); + } + @Test void migrateV211LimitsTest() throws Exception { createNetwork(); diff --git a/network-store-server/src/test/resources/application-default.yml b/network-store-server/src/test/resources/application-default.yml index 3e22ad51..886ba9ea 100644 --- a/network-store-server/src/test/resources/application-default.yml +++ b/network-store-server/src/test/resources/application-default.yml @@ -7,3 +7,10 @@ powsybl-ws: hostPort: ":" name: iidm_${testDbSuffix} customQuery: ~ + +logging: + level: + # suppress db config startup logs, they appear hundred of times + # because we don't reuse spring context to drop the in memory db + com.zaxxer.hikari.HikariConfig: INFO + liquibase: ERROR # too verbose to dump liquibase operations at the begining of each test