[ams][test] Make RestCatalogService nested tests order-independent#4201
[ams][test] Make RestCatalogService nested tests order-independent#4201lintingbin wants to merge 1 commit into
Conversation
The integration tests under amoro-ams/src/test/java/org/apache/amoro/server/TestInternal*CatalogService share a static AmsEnvironment instance and a hard-coded "test_ns" database / "test_iceberg_tbl" table name across every @nested class. Whenever cleanup leaks (the existing @AfterEach swallows dropDatabase exceptions) or background scans race the tests, sibling @nested classes inherit dirty catalog state and assertions that hard-code the catalog being empty start failing. Concrete fixes: * Each test instance now picks a fresh database name via a static AtomicLong counter ("test_ns_<n>"), so unrelated tests can never collide on the same namespace even if a previous run leaked state. * TestInternalMixedCatalogService.TestDatabaseOperation.test now asserts the create / drop delta against the initial database and namespace counts instead of asserting the catalog is empty. * TestInternalIcebergCatalogService.NamespaceTests.testNamespaceOperations has the same delta-based fix. This addresses the same pre-existing flakiness seen on master CI (see Core/hadoop3 run on 2026-04-23 failing in TestInternalIcebergCatalogService$CatalogPropertiesTest's suite) and the failures reproduced on PR apache#4200 CI in TestInternalMixedCatalogService$TestDatabaseOperation / TestTableOperation / TestTableCommit.
|
Hi @zhoujinsong, would you mind taking a look when you have time? Thanks! This is test-only and is meant to fix the flaky |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@amoro.apache.org list. Thank you for your contributions. |
What changes were proposed in this pull request?
amoro-ams/src/test/java/org/apache/amoro/server/RestCatalogServiceTestBaseand its subclasses (TestInternalMixedCatalogService,TestInternalIcebergCatalogService) share a single staticAmsEnvironmentand a hard-codeddatabase = \"test_ns\"/table = \"test_iceberg_tbl\"across every@Nestedclass. Whenever cleanup leaks (the existing@AfterEachswallowsdropDatabaseexceptions) or background catalog scans race the tests, sibling nested classes inherit dirty catalog state and assertions that hard-code the catalog being empty start failing.This PR makes the tests order-independent without restructuring the suite:
RestCatalogServiceTestBase.databaseis now\"test_ns_\" + COUNTER.incrementAndGet(). Each test method gets a fresh test instance (JUnit 5 defaultLifecycle.PER_METHOD), so each test gets a fresh database name. Pollution between tests can no longer causeAlreadyExistsoncreateDatabaseor pre-populated catalog snapshots.TestInternalMixedCatalogService.TestDatabaseOperation.testandTestInternalIcebergCatalogService.NamespaceTests.testNamespaceOperations. The previous code assertedcatalog.listDatabases().isEmpty()which only holds in a single-test-class-per-JVM execution.Why are the changes needed?
These tests have been flaky on
masterfor a while — for example, theCore/hadoop3 CIrun on 2026-04-23 failed insideTestInternalIcebergCatalogService\$CatalogPropertiesTest's suite, and PR #4200's CI just hit the same family of failures, all surfacing the same root cause:The shared
test_ns/test_iceberg_tblnames are the load-bearing reason these races collide. With unique per-instance database names, every test gets its own namespace, so concurrent or leaked cleanup from a sibling test no longer touches it.This is complementary to #4185, which fixed a
Version-N-already-existsrace inInternalMixedIcebergHandler.newTableOperationstriggered by the same shared-state pattern.How was this patch tested?
Ran the affected suites locally on Java 11:
./mvnw spotless:check checkstyle:check -pl amoro-ams -amis clean.Does this PR introduce any user-facing change?
No — test-only change.