jerryshao opened a new issue, #12504:
URL: https://github.com/apache/gravitino/issues/12504
### Version
main branch
### Describe what's wrong
`TestCatalogManager.testCatalogCacheRemoveListener` asserts that
invalidating exactly one catalog cache entry fires its removal listener exactly
once. It fails intermittently with more removals observed than expected,
because `catalogManager` (and its underlying `getCatalogCache()`) is created
once in a `static` `@BeforeAll` and shared across every test method in the
class. The `@BeforeEach`/`@AfterEach` `reset()` only clears `entityStore`,
never the catalog cache — so cache state (and registered listeners, since
`CatalogManager` has no API to remove a previously-added listener) accumulates
across the whole test class. The test's outcome depends on which other test
methods ran before it and what they did to the shared cache.
### Error message and/or stacktrace
```
TestCatalogManager > testCatalogCacheRemoveListener() FAILED
org.awaitility.core.ConditionTimeoutException: Assertion condition
defined as a Lambda expression in
org.apache.gravitino.catalog.TestCatalogManager Only one catalog should be
removed ==> expected: <1> but was: <5> within 5 seconds.
at
app//org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:167)
at
app//org.awaitility.core.AssertionCondition.await(AssertionCondition.java:119)
at
app//org.awaitility.core.AssertionCondition.await(AssertionCondition.java:31)
at
app//org.awaitility.core.ConditionFactory.until(ConditionFactory.java:1006)
at
app//org.awaitility.core.ConditionFactory.untilAsserted(ConditionFactory.java:790)
at
app//org.apache.gravitino.catalog.TestCatalogManager.testCatalogCacheRemoveListener(TestCatalogManager.java:1325)
Caused by:
org.opentest4j.AssertionFailedError: Only one catalog should be
removed ==> expected: <1> but was: <5>
at
app//org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)
at
app//org.junit.jupiter.api.AssertionUtils.failNotEqual(AssertionUtils.java:62)
at
app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:150)
at
app//org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:559)
at
app//org.apache.gravitino.catalog.TestCatalogManager.lambda$testCatalogCacheRemoveListener$36(TestCatalogManager.java:1330)
```
### How to reproduce
1. On `main`, run the full `TestCatalogManager` test class (not just this
one test in isolation): `./gradlew :core:test --tests
"org.apache.gravitino.catalog.TestCatalogManager"`.
2. Whether `testCatalogCacheRemoveListener` passes or fails depends on which
other test methods in the class ran first and what cache activity they
triggered — running only this single test method in isolation is expected to
pass reliably.
### Additional context
Root cause:
`core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java` —
`catalogManager` is a `static` field initialized once in `@BeforeAll` (lines
~107-121); the shared `reset()` (`@BeforeEach`/`@AfterEach`, lines ~123-128)
only clears `entityStore`, not `catalogManager.getCatalogCache()`.
`CatalogManager.addCatalogCacheRemoveListener(...)` also has no corresponding
method to remove a listener, so listeners registered by one test persist for
the rest of the class. Likely fix: reset/invalidate the catalog cache (and
clear any registered listeners) in the shared `reset()` method, or give this
specific test its own isolated `CatalogManager` instance instead of using the
shared static one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]