Skip to content

Commit 615c7e8

Browse files
authored
Fix flaky TestInternalMixedCatalogService by hardening test cleanup (#4165)
* Fix flaky TestInternalMixedCatalogService by hardening test cleanup When a test method fails mid-way after creating a table but before dropping it, the @AfterEach cleanup could not drop the non-empty database. This left residual state that caused cascading failures in subsequent nested test classes (Database already exists, assertion on listDatabases().isEmpty(), etc.). - CompatibilityCatalogTests.cleanDatabase: drop residual table before dropping database, wrap both in try-catch - TestTableCommit.after: guard dropTable with tableExists check, wrap in try-catch to prevent cascading cleanup failures Signed-off-by: Jiwon Park <jpark92@outlook.kr> * Wrap dropDatabase in try-catch in TestTableOperation cleanup Add missing try-catch around dropDatabase in TestTableOperation.after() for consistency with TestTableCommit and CompatibilityCatalogTests cleanup methods. Signed-off-by: Jiwon Park <jpark92@outlook.kr> --------- Signed-off-by: Jiwon Park <jpark92@outlook.kr>
1 parent 05ff059 commit 615c7e8

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

amoro-ams/src/test/java/org/apache/amoro/server/TestInternalMixedCatalogService.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,11 @@ public void after() {
197197
} catch (Exception e) {
198198
LOG.warn("Failed to drop table during cleanup", e);
199199
}
200-
catalog.dropDatabase(database);
200+
try {
201+
catalog.dropDatabase(database);
202+
} catch (Exception e) {
203+
LOG.warn("Failed to drop database during cleanup", e);
204+
}
201205
}
202206

203207
@ParameterizedTest(name = "CatalogTableOperationTest[withPrimaryKey={0}]")
@@ -257,8 +261,18 @@ public void before() {
257261

258262
@AfterEach
259263
public void after() {
260-
catalog.dropTable(tableIdentifier, true);
261-
catalog.dropDatabase(database);
264+
try {
265+
if (catalog.tableExists(tableIdentifier)) {
266+
catalog.dropTable(tableIdentifier, true);
267+
}
268+
} catch (Exception e) {
269+
LOG.warn("Failed to drop table during cleanup", e);
270+
}
271+
try {
272+
catalog.dropDatabase(database);
273+
} catch (Exception e) {
274+
LOG.warn("Failed to drop database during cleanup", e);
275+
}
262276
}
263277

264278
@ParameterizedTest(name = "TableCommitTest[withPrimaryKey={0}]")
@@ -320,7 +334,18 @@ public void setupTest() {
320334

321335
@AfterEach
322336
public void cleanDatabase() {
323-
catalog.dropDatabase(database);
337+
try {
338+
if (catalog.tableExists(tableIdentifier)) {
339+
catalog.dropTable(tableIdentifier, true);
340+
}
341+
} catch (Exception e) {
342+
LOG.warn("Failed to drop table during cleanup", e);
343+
}
344+
try {
345+
catalog.dropDatabase(database);
346+
} catch (Exception e) {
347+
LOG.warn("Failed to drop database during cleanup", e);
348+
}
324349
}
325350

326351
@ParameterizedTest(name = "Test-NewCatalog-Load-HistoricalTable[withPrimaryKey={0}]")

0 commit comments

Comments
 (0)