Skip to content

Commit

Permalink
Merge pull request #161 from chrisvest/fix-flaky-test
Browse files Browse the repository at this point in the history
Fix flaky ThreadedPoolTest.mustNotHoldOnToDeallocatedObjectsWhenLeakDetectionIsEnabled
  • Loading branch information
chrisvest committed May 27, 2024
2 parents 1cfe94f + de9f791 commit b59011d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/test/java/blackbox/AllocatorBasedPoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1681,13 +1681,14 @@ void mustNotHoldOnToDeallocatedObjectsWhenLeakDetectionIsEnabled()
// Clear the allocator lists to remove the last references
allocator.clearLists();

// GC to force the object through finalization life cycle
System.gc();
System.gc();
System.gc();
int iterationCount = 0;
do {
// GC to force the object through finalization life cycle
System.gc();
assertThat(iterationCount++).isLessThan(1000);

// Now our weakReference must have been cleared
assertNull(weakReference.get());
// Now our weakReference must eventually have been cleared
} while (weakReference.get() != null);
}

@Test
Expand Down
6 changes: 0 additions & 6 deletions src/test/java/blackbox/DefaultPoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,4 @@ class DefaultPoolTest extends ThreadBasedPoolTest {
protected PoolBuilder<GenericPoolable> 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);
}
}
18 changes: 18 additions & 0 deletions src/test/java/blackbox/ThreadBasedPoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,22 @@ void newBgAllocatedObjectsMustBeClaimedAheadOfExistingLiveObjects(Taps taps) thr
d.release();
}
}

@Override
void claimWhenInterruptedMustNotThrowIfObjectIsAvailableViaCache(Taps taps) throws Exception {
noBackgroundExpirationChecking(); // Prevent background expiration checking from claiming cached object.
super.claimWhenInterruptedMustNotThrowIfObjectIsAvailableViaCache(taps);
}

@Override
void mustNotHoldOnToDeallocatedObjectsWhenLeakDetectionIsEnabled() throws Exception {
noBackgroundExpirationChecking();
super.mustNotHoldOnToDeallocatedObjectsWhenLeakDetectionIsEnabled();
}

@Override
void tryClaimMustReturnIfPoolIsNotEmpty(Taps taps) throws Exception {
noBackgroundExpirationChecking();
super.tryClaimMustReturnIfPoolIsNotEmpty(taps);
}
}

0 comments on commit b59011d

Please sign in to comment.