spring-projects / spring-projects/spring-framework

Property value from context is unexpected when run junit tests in parallel (context corrupted?)

Open
#34,339 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: test status: waiting-for-triage
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

Description
Integration tests in a Spring Boot application run in parallel and set a variable using @DynamicPropertySource. Each test is expected to start its own Spring context with separate beans and properties, but properties value is unexpectedly overwritten by other tests.

Reproducer
A small reproducer for the issue has been prepared: GitHub Repository (Java 21, Kotlin, Gradle).

During execution, each test launches a Spring Batch job, passing the assigned parameter value. The job then verifies that this value matches the one in its context. When tests run in parallel, some of them fail because the expected and actual values do not match.

However, when running tests sequentially (without parallelization), all tests pass successfully.

What was tried

  • set property with @TestPropertySource for each test
  • use different value for @ActiveProfiles for each test

How to reproduce
Clone https://github.com/verusikk/spring-boot-integration-tests-issue, use README.md commands to run integration tests.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Clone the linked reproducer and follow its README.md commands to run the integration tests. Compare parallel execution with sequential execution and inspect how @DynamicPropertySource and Spring test contexts are used. Done means identifying the context or property isolation issue and confirming that the parallel tests consistently retain their assigned values.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin, spring
Domain
backend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.