Fix wrong use of assertTrue in unit test.
Motivation: My previous commit b88a980482d2ae introduced a flawed unit test, that executes an assertion in a different thread than the test thread. If this assertion fails, the test doesn't fail. Modifications: Replace the assertion by a proper workaround. Result: More correct unit test
This commit is contained in:
parent
1090d7200d
commit
a42bf5495e
@ -26,6 +26,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
@ -41,6 +42,8 @@ public class PooledByteBufAllocatorTest {
|
||||
final PooledByteBufAllocator allocator =
|
||||
new PooledByteBufAllocator(numArenas, numArenas, 8192, 1);
|
||||
|
||||
final AtomicBoolean threadCachesCreated = new AtomicBoolean(true);
|
||||
|
||||
for (int i = 0; i < numArenas; i++) {
|
||||
new FastThreadLocalThread(new Runnable() {
|
||||
@Override
|
||||
@ -50,7 +53,12 @@ public class PooledByteBufAllocatorTest {
|
||||
buf.writeByte(0);
|
||||
}
|
||||
|
||||
assertTrue(allocator.numThreadLocalCaches() > 0);
|
||||
// Make sure that thread caches are actually created,
|
||||
// so that down below we are not testing for zero
|
||||
// thread caches without any of them ever having been initialized.
|
||||
if (allocator.numThreadLocalCaches() == 0) {
|
||||
threadCachesCreated.set(false);
|
||||
}
|
||||
|
||||
buf.release();
|
||||
}
|
||||
@ -61,6 +69,8 @@ public class PooledByteBufAllocatorTest {
|
||||
while (allocator.numThreadLocalCaches() > 0) {
|
||||
LockSupport.parkNanos(MILLISECONDS.toNanos(100));
|
||||
}
|
||||
|
||||
assertTrue(threadCachesCreated.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user