Skip to content

Commit

Permalink
Fix a flaky test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chrisvest committed Jun 30, 2024
1 parent ef684c7 commit 9184cfd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/test/java/blackbox/AllocatorBasedPoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 9184cfd

Please sign in to comment.