Skip to content

Commit 9c4d48e

Browse files
authored
Fix flaky SingleThreadEventExecutorTest.testNotSuspendedUntilSchedule… (#15256)
…dTaskIsCancelled Motivation: The testNotSuspendedUntilScheduledTaskIsCancelled was flaky the removal of the scheduled task from the internal task queue might be offloaded to the eventloop and so may take a moment Modifications: - Change assert to loop and add a timeout Result: Test should not be flaky anymore
1 parent aa4ef8d commit 9c4d48e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎common/src/test/java/io/netty/util/concurrent/SingleThreadEventExecutorTest.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ void testSuspension() throws Exception {
146146
}
147147

148148
@Test
149+
@Timeout(value = 10, unit = TimeUnit.SECONDS)
149150
void testNotSuspendedUntilScheduledTaskIsCancelled() throws Exception {
150151
TestThreadFactory threadFactory = new TestThreadFactory();
151152
final SingleThreadEventExecutor executor = new SuspendingSingleThreadEventExecutor(threadFactory);
@@ -160,7 +161,12 @@ void testNotSuspendedUntilScheduledTaskIsCancelled() throws Exception {
160161

161162
// Now cancel the task which should allow the suspension to let the thread die once we call trySuspend() again
162163
assertTrue(future.cancel(false));
163-
assertTrue(executor.trySuspend());
164+
future.await();
165+
166+
// Call in a loop as removal of scheduled tasks from task queue might be lazy
167+
while (!executor.trySuspend()) {
168+
Thread.sleep(50);
169+
}
164170

165171
currentThread.join();
166172

0 commit comments

Comments
 (0)