This is an automated email from the ASF dual-hosted git repository.
FrankChen021 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new d311319e736 test: fix flaky ReferenceCountingResourceHolderTest
cleaner checks (#20317)
d311319e736 is described below
commit d311319e7361951f1f7431a3c103db2b74ca4272
Author: Frank Chen <[email protected]>
AuthorDate: Thu Sep 24 10:04:55 2026 +0800
test: fix flaky ReferenceCountingResourceHolderTest cleaner checks (#20317)
The leaked resource counter is global to the JVM and is incremented before
the
closer runs. With reuseForks=true, the forced GC loop can be ended by a
holder
leaked by another test class in the same fork, before this test's closer has
run, so the exact-count assertion and the released check fail
intermittently.
Wait for this test's own released flag instead, and only assert a lower
bound
on the global counter.
---
.../collections/ReferenceCountingResourceHolderTest.java | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git
a/processing/src/test/java/org/apache/druid/collections/ReferenceCountingResourceHolderTest.java
b/processing/src/test/java/org/apache/druid/collections/ReferenceCountingResourceHolderTest.java
index 3d07f522d48..b78e18df329 100644
---
a/processing/src/test/java/org/apache/druid/collections/ReferenceCountingResourceHolderTest.java
+++
b/processing/src/test/java/org/apache/druid/collections/ReferenceCountingResourceHolderTest.java
@@ -116,15 +116,21 @@ public class ReferenceCountingResourceHolderTest
private void verifyCleanerRun(AtomicBoolean released, long
initialLeakedResources) throws InterruptedException
{
- // Wait until Closer runs
- for (int i = 0; i < 6000 &&
ReferenceCountingResourceHolder.leakedResources() == initialLeakedResources;
i++) {
+ // Wait until the Cleaner has run the closer of the holder leaked by this
test. The leaked resource counter is
+ // global to the JVM and is incremented before the closer runs, so it
cannot be used to detect completion: holders
+ // leaked by other tests sharing this JVM may be collected by the forced
GC as well.
+ for (int i = 0; i < 6000 && !released.get(); i++) {
System.gc();
@SuppressWarnings("unused")
byte[] garbage = new byte[10_000_000];
Thread.sleep(10);
}
- Assertions.assertEquals(initialLeakedResources + 1,
ReferenceCountingResourceHolder.leakedResources());
- // Cleaner also runs the closer
+ // Cleaner runs the closer
Assertions.assertTrue(released.get());
+ // At least the holder leaked by this test must have been counted; other
leaked holders may have been counted too.
+ Assertions.assertTrue(
+ ReferenceCountingResourceHolder.leakedResources() >=
initialLeakedResources + 1,
+ "leakedResources should have been incremented at least once"
+ );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]