#Spring Boot, JUnit Jupiter, Testcontainers, OOM

52 messages · Page 1 of 1 (latest)

cosmic fiber
#

If I add too many test classes, I get OOM errors. Memory snapshots at the critical moments contain many DefaultListableBeanFactory instances. The amount of DefaultListableBeanFactory instances grow up after adding new test classes. I have Testcontainers for using a PostgreSQL container. I disable unnecessary components with a test application configuration. Any suggestions? Thanks

ivory ploverBOT
#

This post has been reserved for your question.

Hey @cosmic fiber! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

frozen sky
#

Are you stopping the containers after each test?

cosmic fiber
frozen sky
#

Can you check whether it is actually stopped automatically on each test?

cosmic fiber
vagrant siren
#

seems like there's an infinite loop of spring contexts starting?

cosmic fiber
frozen sky
#

Can you show the @DirtiesContext tests?

#

or one of them

#

I mean, I know there are bugs related to @DirtiesContext but I don't know of any like that

cosmic fiber
# frozen sky Can you show the `@DirtiesContext` tests?

I use this hierarchy:

@Testcontainers
@DirtiesContext
@ActiveProfiles("test-containers")
public abstract class PostgresContainerBaseTest {

@Container
public static final PostgreSQLContainer<?> postgresDB = new PostgreSQLContainer<>
            ("postgres:13.2")
            .withDatabaseName("")
            .withUsername("")
            .withPassword("");
            
@DynamicPropertySource
public static void properties(DynamicPropertyRegistry registry) {}

}

@SpringJUnitConfig
@SpringBootTest(...)
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@Transactional
public abstract class ApplicationContainerBaseTest extends PostgresContainerBaseTest {}

@AutoConfigureMockMvc
class PropertyValueMockMvcTest extends ApplicationContainerBaseTest {

@Autowired
private MockMvc mockMvc;

@Test
void getPropertyValueSuccessfullyTest() {}
}
ivory ploverBOT
frozen sky
#

Also is the @DirtiesContext really necessary?

#

Also, what JUnit version are you using?

cosmic fiber
frozen sky
#

@ClassRule is for JUnit 5 I think

#

well maybe not

#

try not putting the container in a superclass

#

try putting it in the subclasses

cosmic fiber
frozen sky
#

And do these tests mess up the context?

#

like are they changing fields in components or similar?

cosmic fiber
cosmic fiber
cosmic fiber
cosmic fiber
frozen sky
#

and what exactly goes OOM? The JVM running the tests?

cosmic fiber
frozen sky
#

in most cases

cosmic fiber
cosmic fiber
# frozen sky and what exactly goes OOM? The JVM running the tests?

Other system threads show it. Right. Here are some examples:

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "logback-53"
Exception in thread "Catalina-utility-2" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space


cosmic fiber
frozen sky
#

Can you check the memory usage over time? Does it slowly accumulate?

#

Also, can you get a heapdump and analyze it?

cosmic fiber
cosmic fiber
frozen sky
#

or configure it to automatically do a heapdump when the OOM occurs

cosmic fiber
cosmic fiber
frozen sky
#

maybe you have a static field storing your contexts somewhere

cosmic fiber
#

Right! I will try

Now I have 5 ways for the further investigation

ivory ploverBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

cosmic fiber
#

After many hours, I increased the maximum heap memory. It was enough because the application became more heavy. Thank you, Daniel!

ivory ploverBOT