xuxiaowei-com-cn opened a new issue, #8180:
URL: https://github.com/apache/incubator-seata/issues/8180

   ### Check Ahead
   
   - [x] I have searched the [issues](https://github.com/seata/seata/issues) of 
this repository and believe that this is not a duplicate.
   
   - [x] I am willing to try to fix this bug myself.
   
   
   ### Ⅰ. Issue Description
   
   `AuthControllerWithRandomPasswordTest` occasionally fails when running 
alongside all other naming server test classes, but passes reliably when 
executed individually.
   
   <img width="2092" height="1230" alt="Image" 
src="https://github.com/user-attachments/assets/19e6dd70-0ee8-480b-9f30-d53ee48fc0f3";
 />
   
   ### Ⅱ. Describe what happened
   
   
   When all tests under the `namingserver` module are executed together (e.g., 
via `mvn test` or running the entire test suite in the IDE), 
`AuthControllerWithRandomPasswordTest` occasionally fails. The test passes 
reliably when executed in isolation.
   
   The test class is annotated with `@SpringBootTest(webEnvironment = 
SpringBootTest.WebEnvironment.RANDOM_PORT)` and uses `@AutoConfigureMockMvc` to 
test the authentication endpoints. The test relies on parsing the 
auto-generated random password from application startup log output via 
`CapturedOutput`.
   
   When the test runs in isolation, it gets its own fresh Spring Boot 
application context — the server starts, a random password is generated and 
logged, and the test successfully extracts it from the captured output to 
authenticate.
   
   However, when all naming server tests run together, Spring Boot's test 
context caching mechanism may cause context sharing or resource conflicts 
between tests using different `webEnvironment` modes:
   
   | Test Class | webEnvironment | Properties / Notes |
   |---|---|---|
   | `AuthControllerWithRandomPasswordTest` | `RANDOM_PORT` | No explicit 
properties, `@AutoConfigureMockMvc` |
   | `NamingControllerLoggerPrintSmokeTest` | `RANDOM_PORT` | `properties = 
"console.user.password="`, no MockMvc |
   | `NamingControllerPropertiesSmokeTest` | `RANDOM_PORT` | `properties = 
{"console.user.username=seata", "console.user.password=foo"}`, no MockMvc |
   | `AuthControllerWithCustomPropertiesTest` | `MOCK` (default) | 
`@TestPropertySource(properties = {"console.user.username=seata", 
"console.user.password=foo"})` |
   | `WebSecurityConfigTest` | `MOCK` (default) | No extra properties |
   | `NamingControllerTest` | `MOCK` (default) | No extra properties |
   | Other tests | Various | — |
   
   Because the test requires the random password generated at application 
startup (captured via `CapturedOutput`), if the Spring context is reused or the 
startup log output is not fresh, `CapturedOutput.getOut()` will not contain the 
expected `"Use the auto-generated password: [...]"` pattern, causing the 
assertion `assertTrue(matcher.find(), "captured password not found in logs")` 
to fail.
   
   **In IntelliJ IDEA, when you click on a test class, in simple terms: if a 
banner appears, it means the test runs in an isolated context; if no banner 
appears, it means it shares the context with other test classes.**
   
   <img width="2092" height="1230" alt="Image" 
src="https://github.com/user-attachments/assets/b22f47b6-0d9f-4a8c-babf-ee720685f08b";
 />
   
   <img width="2092" height="1230" alt="Image" 
src="https://github.com/user-attachments/assets/639bebb6-7f13-455d-b373-c9ef9f3e41f2";
 />
   
   <img width="2092" height="1230" alt="Image" 
src="https://github.com/user-attachments/assets/f94bdd2a-9111-49f0-a90a-9ca1f23b3cb5";
 />
   
   
   
   ### Ⅲ. Describe what you expected to happen
   
   `AuthControllerWithRandomPasswordTest` should pass both when run 
individually and when run together with all other naming server tests, without 
being affected by context caching or execution order.
   
   
   ### Ⅳ. How to reproduce it (as minimally and precisely as possible)
   
   
   1. Navigate to the `namingserver` module
   2. Run the full test suite:
      ```
      mvn test -pl namingserver
      ```
   3. Observe that `AuthControllerWithRandomPasswordTest` fails
   4. Run the test in isolation:
      ```
      mvn test -pl namingserver -Dtest=AuthControllerWithRandomPasswordTest
      ```
   5. Observe that `AuthControllerWithRandomPasswordTest` passes
   
   
   ### Ⅴ. Anything else we need to know?
   
   
   The test was previously using the default `MOCK` web environment without 
specifying `webEnvironment`. Adding `webEnvironment = 
SpringBootTest.WebEnvironment.RANDOM_PORT` ensures the test gets an independent 
context when run alone. However, when run together with other tests (especially 
other `RANDOM_PORT` tests with different `properties` configurations), the 
context caching behavior of Spring Boot Test framework may still cause issues.
   
   Potential root causes to investigate:
   - Spring Boot test context caching between tests with `RANDOM_PORT` that 
have different `properties` or `@AutoConfigureMockMvc` configurations
   - Shared static state related to the auto-generated password mechanism 
across different test contexts
   - Interaction between `MOCK`-mode and `RANDOM_PORT`-mode `@SpringBootTest` 
contexts when loaded in the same test suite
   
   
   ### Ⅵ. Environment
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to