diff --git a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRule.java b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRule.java index 38f7123e6..ff52095e2 100644 --- a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRule.java +++ b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRule.java @@ -62,7 +62,6 @@ import org.testcontainers.containers.PostgreSQLContainer; abstract class JpaTransactionManagerRule extends ExternalResource { private static final String DB_CLEANUP_SQL_PATH = "google/registry/persistence/transaction/cleanup_database.sql"; - private static final String MANAGEMENT_DB_NAME = "management"; private static final String POSTGRES_DB_NAME = "postgres"; // The type of JDBC connections started by the tests. This string value // is documented in PSQL's official user guide. @@ -95,14 +94,14 @@ abstract class JpaTransactionManagerRule extends ExternalResource { private static JdbcDatabaseContainer create() { PostgreSQLContainer container = new PostgreSQLContainer(NomulusPostgreSql.getDockerTag()) - .withDatabaseName(MANAGEMENT_DB_NAME); + .withDatabaseName(POSTGRES_DB_NAME); container.start(); return container; } @Override public void before() throws Exception { - executeSql(MANAGEMENT_DB_NAME, readSqlInClassPath(DB_CLEANUP_SQL_PATH)); + executeSql(POSTGRES_DB_NAME, readSqlInClassPath(DB_CLEANUP_SQL_PATH)); initScriptPath.ifPresent(path -> executeSql(POSTGRES_DB_NAME, readSqlInClassPath(path))); if (!extraEntityClasses.isEmpty()) { File tempSqlFile = File.createTempFile("tempSqlFile", ".sql"); @@ -156,8 +155,7 @@ abstract class JpaTransactionManagerRule extends ExternalResource { * is less than 5 to reduce flakiness. */ private void assertReasonableNumDbConnections() { - // Use the 'management' db to connect so that this connection needs not to be accounted for. - try (Connection conn = createConnection(MANAGEMENT_DB_NAME); + try (Connection conn = createConnection(POSTGRES_DB_NAME); Statement statement = conn.createStatement()) { // Note: Since we use the admin user (returned by container's getUserName() method) // in tests, we need to filter connections by database name and/or backend type to filter out diff --git a/core/src/test/resources/google/registry/persistence/transaction/cleanup_database.sql b/core/src/test/resources/google/registry/persistence/transaction/cleanup_database.sql index ac5b72a5c..e52360198 100644 --- a/core/src/test/resources/google/registry/persistence/transaction/cleanup_database.sql +++ b/core/src/test/resources/google/registry/persistence/transaction/cleanup_database.sql @@ -12,5 +12,8 @@ -- See the License for the specific language governing permissions and -- limitations under the License. -DROP DATABASE IF EXISTS postgres; -CREATE DATABASE postgres; +-- In Postgresql, recreating schema is faster than recreating the database. +DROP SCHEMA public CASCADE; +CREATE SCHEMA public; +GRANT USAGE ON SCHEMA public to PUBLIC; +GRANT CREATE ON SCHEMA public to PUBLIC;