From ce152e466b890ef2170eb414a0e6aedd4bb52589 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Mon, 27 May 2024 13:45:15 -0700 Subject: [PATCH] Fix flaky DefaultPoolTest The `claimWhenInterruptedMustNotThrowIfObjectIsAvailableViaCache` relies on the thread-local cache having a previously claimed object ready to be reclaimed. However, background expiration checking would sometimes race and claim the object temporarily, preventing a TLR_CLAIM by the test. This would cause the test to go down the slow claim path, which is susceptible to interrupts, and which the test was asserting would not happen. --- src/test/java/blackbox/DefaultPoolTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/blackbox/DefaultPoolTest.java b/src/test/java/blackbox/DefaultPoolTest.java index 146726f6..55a061a9 100644 --- a/src/test/java/blackbox/DefaultPoolTest.java +++ b/src/test/java/blackbox/DefaultPoolTest.java @@ -25,4 +25,10 @@ class DefaultPoolTest extends ThreadBasedPoolTest { protected PoolBuilder createInitialPoolBuilder(AlloKit.CountingAllocator allocator) { return Pool.from(allocator); } + + @Override + void claimWhenInterruptedMustNotThrowIfObjectIsAvailableViaCache(Taps taps) throws Exception { + noBackgroundExpirationChecking(); // Prevent background expiration checking from claiming cached object. + super.claimWhenInterruptedMustNotThrowIfObjectIsAvailableViaCache(taps); + } }