Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky test #170

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/test/java/blackbox/slow/PoolIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.jupiter.api.extension.RegisterExtension;
import stormpot.Completion;
import stormpot.GenericPoolable;
import stormpot.ManagedPool;
import stormpot.Pool;
import stormpot.PoolBuilder;
import stormpot.PoolException;
Expand Down Expand Up @@ -285,10 +286,12 @@ void mustGraduallyReduceAggressivenessInRepairingFailingAllocator() throws Excep
}));
builder.setAllocator(allocator);
createPool();
ManagedPool managedPool = pool.getManagedPool();
GenericPoolable obj = pool.claim(longTimeout);
obj.expire();
obj.release();
assertThrows(PoolException.class, () -> pool.claim(longTimeout).release());
StringBuilder sb = new StringBuilder(1024);
long prev = 0, curr;
for (int i = 0; i < 50; i++) {
long start = System.nanoTime();
Expand All @@ -297,14 +300,22 @@ void mustGraduallyReduceAggressivenessInRepairingFailingAllocator() throws Excep
if (elapsedMillis >= 150) {
// Ignore outliers with very high sleep time.
i--;
prev = counter.get();
continue;
}
curr = counter.get();
long delta = curr - prev;
sb.append("i = ").append(i).append(", delta = ").append(delta)
.append(", alloc ratio = ")
.append(managedPool.getAllocationCount()).append('/').append(managedPool.getFailedAllocationCount())
.append('\n');
prev = curr;
if (i > 40) {
if (delta > 5) {
}
assertThat(delta).isLessThanOrEqualTo(5);
}
}
System.out.print(sb);
}
}
Loading