Skip to content

Commit 4d7c96a

Browse files
committed
Stop EmbeddedPostgres instance on JVM shutdown
1 parent a5297e3 commit 4d7c96a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test-support/src/main/java/org/jabref/support/JournalAbbreviationTestUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jabref.support;
22

3+
import java.io.IOException;
34
import java.sql.Connection;
45
import java.sql.Statement;
56

@@ -25,6 +26,16 @@ public static synchronized DataSource getDataSource() throws Exception {
2526
}
2627
// Pre-populate once so parallel test workers never race on table creation
2728
JournalAbbreviationLoader.loadBuiltInRepository(dataSource);
29+
30+
// Stop the embedded Postgres instance when the JVM shuts down
31+
final EmbeddedPostgres pgToClose = pg;
32+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
33+
try {
34+
pgToClose.close();
35+
} catch (IOException e) {
36+
// best effort cleanup
37+
}
38+
}));
2839
}
2940
return dataSource;
3041
}

0 commit comments

Comments
 (0)