Skip to content

Commit 2a8c707

Browse files
committed
test: stop global spring.profiles.active pollution that flaked RegistrationGuard wiring tests
BaseTestConfiguration set spring.profiles.active=test via System.setProperty, a JVM-global mutation that leaked across the parallel test suite. When it raced ahead of RegistrationGuardConfigurationTest — which runs an ApplicationContextRunner with no profile and gates its consumer-guard configs on @Profile("!test") — the test profile suppressed those guards, so DefaultRegistrationGuard was registered and two wiring assertions failed (intermittently; surfaced on the Java 25 run). The property was redundant: every test annotation and direct consumer already declares @activeprofiles("test"), and ddl-auto/datasource are set in the test properties files. Removed the TestPropertySourcesConfigurer entirely. Also pinned RegistrationGuardConfigurationTest's runner to a non-test profile via withPropertyValues so it stays deterministic against any future ambient leak.
1 parent 7d05a8c commit 2a8c707

2 files changed

Lines changed: 7 additions & 20 deletions

File tree

src/test/java/com/digitalsanctuary/spring/user/registration/RegistrationGuardConfigurationTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ class RegistrationGuardConfigurationTest {
3232
// Register RegistrationGuardConfiguration as an auto-configuration so its @ConditionalOnMissingBean
3333
// evaluates AFTER any consumer-supplied guard beans — mirroring production, where this configuration
3434
// is component-scanned by the UserConfiguration auto-configuration (loaded after consumer beans).
35+
//
36+
// The inlined "spring.profiles.active" pins this context to a non-"test" profile so the @Profile("!test")
37+
// guard configs below always load. Without it, the test depends on no "test" profile being active — a
38+
// fragile assumption, because anything that sets the global "spring.profiles.active=test" system property
39+
// (e.g. another test running concurrently) would suppress the guard configs and flake these assertions.
40+
// The inlined property source outranks any leaked system property, making this deterministic.
3541
private final ApplicationContextRunner runner = new ApplicationContextRunner()
42+
.withPropertyValues("spring.profiles.active=registrationguardtest")
3643
.withConfiguration(AutoConfigurations.of(RegistrationGuardConfiguration.class));
3744

3845
@Test

src/test/java/com/digitalsanctuary/spring/user/test/config/BaseTestConfiguration.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,4 @@ public Locale testLocale() {
8383
return Locale.US;
8484
}
8585

86-
/**
87-
* Test-specific property overrides.
88-
*/
89-
@Bean
90-
public TestPropertySourcesConfigurer testPropertySourcesConfigurer() {
91-
return new TestPropertySourcesConfigurer();
92-
}
93-
94-
/**
95-
* Helper class to configure test properties programmatically.
96-
*/
97-
public static class TestPropertySourcesConfigurer {
98-
99-
public TestPropertySourcesConfigurer() {
100-
// Set system properties for tests
101-
System.setProperty("spring.profiles.active", "test");
102-
System.setProperty("spring.jpa.hibernate.ddl-auto", "create-drop");
103-
System.setProperty("spring.datasource.initialization-mode", "always");
104-
}
105-
}
10686
}

0 commit comments

Comments
 (0)