From 95b91cb6fada6c72acce2721556dd49b3868b75a Mon Sep 17 00:00:00 2001 From: Lars Bilger Date: Wed, 4 Oct 2023 11:14:03 +0200 Subject: [PATCH] fix: try to make itests work Fixes #874 --- view/jpa/src/test/resources/application-itest.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/view/jpa/src/test/resources/application-itest.yaml b/view/jpa/src/test/resources/application-itest.yaml index 926bb0e01..5f179fe48 100644 --- a/view/jpa/src/test/resources/application-itest.yaml +++ b/view/jpa/src/test/resources/application-itest.yaml @@ -6,7 +6,11 @@ spring: generate-ddl: true hibernate.ddl-auto: create-drop datasource: - url: jdbc:h2:mem:testdb;MODE=PostgreSQL;INIT=create schema if not exists PUBLIC;DB_CLOSE_DELAY=-1;NON_KEYWORDS=VALUE;DB_CLOSE_ON_EXIT=FALSE + # Explanation for the `random.uuid`: Spring caches application contexts for tests (see https://docs.spring.io/spring-framework/reference/testing/testcontext-framework/ctx-management/caching.html). + # If each context uses the same database, we can get a situation where context A is initialized, then context B is initialized and shut down, then context A is reused. But the + # shutdown of context B has destroyed (dropped the schema of) the shared database, so the second test using context A will find the database in an unexpected state and fails. + # Adding a random identifier to the database name ensures that each context gets its own database that it can initialize and tear down according to its own lifecycle. + url: jdbc:h2:mem:testdb-${random.uuid};MODE=PostgreSQL;INIT=create schema if not exists PUBLIC;DB_CLOSE_DELAY=-1;NON_KEYWORDS=VALUE username: sa password: sa hikari: