From 28aa31ca5492c75eeebda71f5ceefc3ab97e034c Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 18 Feb 2024 20:12:19 +0100 Subject: [PATCH] fix: Without `@DirtiesContext` the app is not teared down correctly * `StorageStrategy` depends on Spring to call the method `ChatBackendApplication#onExit()`, that is annotated with `@PreDestroy`. * If this method is not called, the strategy is not applied, which leads to errors in the integration-tests. * This happens, if all tests are run through Maven, because Spring recycles the application-context and only tears down the context after all tests have run. * The addition of `@DirtiesContext` on those tests forces Spring to tear down the application completely after each so annotated test. * Hence, the method is called as expected, which fixes the described errors. --- .../de/juplo/kafka/chat/backend/AbstractConfigurationIT.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java b/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java index 41618e56..21605bc1 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.MediaType; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.web.reactive.server.WebTestClient; import org.testcontainers.shaded.org.awaitility.Awaitility; @@ -22,6 +23,7 @@ import static org.hamcrest.Matchers.endsWith; @Slf4j +@DirtiesContext public abstract class AbstractConfigurationIT { final static String EXISTING_CHATROOM = "5c73531c-6fc4-426c-adcb-afc5c140a0f7"; -- 2.20.1