Skip to content

Commit

Permalink
Fix: make repository tests independant (#94)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
etiennehomer authored Jan 29, 2025
1 parent f7a338a commit 63ca2ab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,29 @@
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");

@Autowired
private NetworkStoreRepository networkStoreRepository;

@DynamicPropertySource
static void makeTestDbSuffix(DynamicPropertyRegistry registry) {
UUID uuid = UUID.randomUUID();
registry.add("testDbSuffix", () -> uuid);
}

@Test
void insertTemporaryLimitsInLinesTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 63ca2ab

Please sign in to comment.