GeezerVison is showing github.com — Try to fix/stabilize a number of flaky tests (#16934) (#17763) · netty/netty@ac4ea46
File treeExpand file treeCollapse file tree Open diff view settings buffer/src/test/java/io/netty/buffer common/src/main/java/io/netty/util/internal transport/src/test/java/io/netty/channel/nio
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2816,9 +2816,9 @@ public void run() { | 2816 | 2816 | while (latch.getCount() > 0) { | 2817 | 2817 | ByteBuf buf; | 2818 | 2818 | if (slice) { | 2819 | | - buf = buffer.slice(); | | 2819 | + buf = buffer.slice(); | 2820 | 2820 | } else { | 2821 | | - buf = buffer.duplicate(); | | 2821 | + buf = buffer.duplicate(); | 2822 | 2822 | } | 2823 | 2823 | TestGatheringByteChannel channel = new TestGatheringByteChannel(); | 2824 | 2824 |
| @@ -2847,7 +2847,7 @@ public void run() { | 2847 | 2847 | } | 2848 | 2848 | try { | 2849 | 2849 | latch.await(); | 2850 | | - barrier.await(5, TimeUnit.SECONDS); | | 2850 | + barrier.await(30, TimeUnit.SECONDS); | 2851 | 2851 | } catch (Exception e) { | 2852 | 2852 | Throwable inner = innerThrowable.get(); | 2853 | 2853 | if (inner != null) { | @@ -2931,7 +2931,7 @@ public void run() { | 2931 | 2931 | } | 2932 | 2932 | try { | 2933 | 2933 | latch.await(); | 2934 | | - barrier.await(5, TimeUnit.SECONDS); | | 2934 | + barrier.await(30, TimeUnit.SECONDS); | 2935 | 2935 | } catch (Exception e) { | 2936 | 2936 | Throwable inner = innerThrowable.get(); | 2937 | 2937 | if (inner != null) { | |
Collapse file Copy file name to clipboardExpand all lines: buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java +11-3Lines changed: 11 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 30 | 30 | import java.util.List; | 31 | 31 | import java.util.Queue; | 32 | 32 | import java.util.Random; | | 33 | +import java.util.concurrent.CompletionException; | 33 | 34 | import java.util.concurrent.ConcurrentLinkedQueue; | 34 | 35 | import java.util.concurrent.CountDownLatch; | 35 | 36 | import java.util.concurrent.FutureTask; | @@ -431,7 +432,7 @@ public void run() { | 431 | 432 | } | 432 | 433 |
| 433 | 434 | @Test | 434 | | - @Timeout(10) | | 435 | + @Timeout(30) | 435 | 436 | public void testNumThreadCachesWithNoDirectArenas() throws Exception { | 436 | 437 | int numHeapArenas = 1; | 437 | 438 | final PooledByteBufAllocator allocator = | @@ -451,7 +452,7 @@ public void testNumThreadCachesWithNoDirectArenas() throws Exception { | 451 | 452 | } | 452 | 453 |
| 453 | 454 | @Test | 454 | | - @Timeout(10) | | 455 | + @Timeout(30) | 455 | 456 | public void testNumThreadCachesAccountForDirectAndHeapArenas() throws Exception { | 456 | 457 | int numArenas = 1; | 457 | 458 | final PooledByteBufAllocator allocator = | @@ -471,7 +472,7 @@ public void testNumThreadCachesAccountForDirectAndHeapArenas() throws Exception | 471 | 472 | } | 472 | 473 |
| 473 | 474 | @Test | 474 | | - @Timeout(10) | | 475 | + @Timeout(30) | 475 | 476 | public void testThreadCacheToArenaMappings() throws Exception { | 476 | 477 | int numArenas = 2; | 477 | 478 | final PooledByteBufAllocator allocator = | @@ -561,6 +562,13 @@ public void destroy() throws Exception { | 561 | 562 | task.get(); | 562 | 563 | t.join(); | 563 | 564 | } catch (InterruptedException e) { | | 565 | + if (task.isDone()) { | | 566 | + try { | | 567 | + task.get(); | | 568 | + } catch (Exception taskException) { | | 569 | + e.addSuppressed(new CompletionException("Task failed", taskException)); | | 570 | + } | | 571 | + } | 564 | 572 | ThrowableUtil.interruptAndAttachAsyncStackTrace(t, e); | 565 | 573 | throw e; | 566 | 574 | } | |
Collapse file Copy file name to clipboardExpand all lines: common/src/main/java/io/netty/util/internal/ThrowableUtil.java +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -92,9 +92,10 @@ public static Throwable[] getSuppressed(Throwable source) { | 92 | 92 | * @param cause The cause to attach a stack trace to. | 93 | 93 | */ | 94 | 94 | public static void interruptAndAttachAsyncStackTrace(Thread thread, Throwable cause) { | | 95 | + Thread.State state = thread.getState(); | 95 | 96 | StackTraceElement[] stackTrace = thread.getStackTrace(); | 96 | 97 | InterruptedException asyncIE = new InterruptedException( | 97 | | - "Asynchronous interruption: " + thread); | | 98 | + "Asynchronous interruption: " + thread + " (" + state + ')'); | 98 | 99 | thread.interrupt(); | 99 | 100 | asyncIE.setStackTrace(stackTrace); | 100 | 101 | addSuppressed(cause, asyncIE); | |
Collapse file Copy file name to clipboardExpand all lines: transport/src/test/java/io/netty/channel/nio/NioEventLoopTest.java +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -201,14 +201,15 @@ public void channelUnregistered(SocketChannel ch, Throwable cause) { | 201 | 201 | @Test | 202 | 202 | public void testTaskRemovalOnShutdownThrowsNoUnsupportedOperationException() throws Exception { | 203 | 203 | final AtomicReference<Throwable> error = new AtomicReference<Throwable>(); | | 204 | + final AtomicBoolean loopStarted = new AtomicBoolean(); | 204 | 205 | final Runnable task = new Runnable() { | 205 | 206 | @Override | 206 | 207 | public void run() { | 207 | 208 | // NOOP | 208 | 209 | } | 209 | 210 | }; | 210 | 211 | // Just run often enough to trigger it normally. | 211 | | - for (int i = 0; i < 1000; i++) { | | 212 | + for (int i = 0; i < 250; i++) { | 212 | 213 | NioEventLoopGroup group = new NioEventLoopGroup(1); | 213 | 214 | final NioEventLoop loop = (NioEventLoop) group.next(); | 214 | 215 |
| @@ -218,18 +219,23 @@ public void run() { | 218 | 219 | try { | 219 | 220 | for (;;) { | 220 | 221 | loop.execute(task); | | 222 | + loopStarted.set(true); | 221 | 223 | } | 222 | 224 | } catch (Throwable cause) { | 223 | 225 | error.set(cause); | 224 | 226 | } | 225 | 227 | } | 226 | 228 | }); | 227 | 229 | t.start(); | | 230 | + do { | | 231 | + Thread.yield(); | | 232 | + } while (!loopStarted.get()); | 228 | 233 | group.shutdownNow(); | 229 | 234 | t.join(); | 230 | 235 | group.terminationFuture().syncUninterruptibly(); | 231 | 236 | assertInstanceOf(RejectedExecutionException.class, error.get()); | 232 | 237 | error.set(null); | | 238 | + loopStarted.set(false); | 233 | 239 | } | 234 | 240 | } | 235 | 241 |
| |
|