From 9184cfd2ca25d03c047a102ed7c5ea24872f9cc5 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Sat, 29 Jun 2024 17:44:01 -0700 Subject: [PATCH] Fix a flaky test The ManagedPool.getAllocationCount is eventually-consistent, and might not have been updated by the time we check. The AlloKit.CountingReallocator increments before the allocated object is available to be claimed. --- src/test/java/blackbox/AllocatorBasedPoolTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/java/blackbox/AllocatorBasedPoolTest.java b/src/test/java/blackbox/AllocatorBasedPoolTest.java index 16977772..bc38b862 100644 --- a/src/test/java/blackbox/AllocatorBasedPoolTest.java +++ b/src/test/java/blackbox/AllocatorBasedPoolTest.java @@ -19,6 +19,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; +import stormpot.AlloKit; import stormpot.Allocator; import stormpot.Completion; import stormpot.Expiration; @@ -824,9 +825,10 @@ void mustStillBeUsableAfterExceptionInAllocate(Taps taps) throws Exception { @ParameterizedTest @EnumSource(Taps.class) void mustStillBeUsableAfterExceptionInReallocate(Taps taps) throws Exception { - builder.setAllocator(reallocator( - alloc($new), - realloc($throw(new RuntimeException("boo from realloc"))))); + AlloKit.CountingReallocator alloc = reallocator( + alloc($new), + realloc($throw(new RuntimeException("boo from realloc")))); + builder.setAllocator(alloc); builder.setExpiration(Expiration.never()); noBackgroundExpirationChecking(); createPool(); @@ -838,7 +840,7 @@ void mustStillBeUsableAfterExceptionInReallocate(Taps taps) throws Exception { tap.claim(longTimeout).release(); // if "claim" doesn't throw, then the background thread might have cleaned up the poisoned // slot before we could get to it. In that case, the allocation count should be 2. - assertThat(pool.getManagedPool().getAllocationCount()).isEqualTo(2); + assertThat(alloc.countAllocations()).isEqualTo(2); } catch (PoolException ignore) {} GenericPoolable claim = tap.claim(longTimeout); assertThat(claim).isNotNull();