Repository: netty/netty
File: common/src/test/java/io/netty/util/concurrent/SingleThreadEventExecutorTest.java (Java)

Code before:
        while ((currentThread = threadFactory.threads.poll()) != null) {
            currentThread.join();
        }
    }

    @Test
    void testSuspensionWhenExecutorIsNotStarted() throws Exception {
        TestThreadFactory threadFactory = new TestThreadFactory();
        final SingleThreadEventExecutor executor = new SuspendingSingleThreadEventExecutor(threadFactory);
        // suspend when executor is not started yet
        assertTrue(executor.trySuspend());
        assertTrue(executor.isSuspended());

        // recover from suspension by executing a task
        LatchTask task1 = new LatchTask();
        executor.execute(task1);
        Thread currentThread = threadFactory.threads.take();
        assertFalse(executor.isSuspended());
        task1.await();

        executor.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly();
        currentThread.join();
        assertFalse(executor.isSuspended());
        assertTrue(executor.isShutdown());

        // Guarantee that al tasks were able to die...
        while ((currentThread = threadFactory.threads.poll()) != null) {
            currentThread.join();
        }
    }

    @Test
    @Timeout(value = 10, unit = TimeUnit.SECONDS)
    void testNotSuspendedUntilScheduledTaskIsCancelled() throws Exception {
        TestThreadFactory threadFactory = new TestThreadFactory();
        final SingleThreadEventExecutor executor = new SuspendingSingleThreadEventExecutor(threadFactory);

        // Schedule a task which is so far in the future that we are sure it will not run at all.
        Future<?> future = executor.schedule(() -> { }, 1, TimeUnit.DAYS);
        TestThread currentThread = threadFactory.threads.take();
        // Let's wait until the thread is started
        currentThread.awaitStarted();
        currentThread.awaitRunnableExecution();
        assertTrue(executor.trySuspend());

        // Now cancel the task which should allow the suspension to let the thread die once we call trySuspend() again
        assertTrue(future.cancel(false));
        future.await();

        // Call in a loop as removal of scheduled tasks from task queue might be lazy
        while (!executor.trySuspend()) {

Review comment (suggestion):
```suggestion
        // Guarantee that all threads were able to die...
```

Code after:
        while ((currentThread = threadFactory.threads.poll()) != null) {
            currentThread.join();
        }
    }

    @Test
    void testSuspensionWhenExecutorIsNotStarted() throws Exception {
        TestThreadFactory threadFactory = new TestThreadFactory();
        final SingleThreadEventExecutor executor = new SuspendingSingleThreadEventExecutor(threadFactory);
        // suspend when executor is not started yet
        assertTrue(executor.trySuspend());
        assertTrue(executor.isSuspended());

        // recover from suspension by executing a task
        LatchTask task1 = new LatchTask();
        executor.execute(task1);
        Thread currentThread = threadFactory.threads.take();
        assertFalse(executor.isSuspended());
        task1.await();

        executor.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly();
        currentThread.join();
        assertFalse(executor.isSuspended());
        assertTrue(executor.isShutdown());

        // Guarantee that all threads were able to die...
        while ((currentThread = threadFactory.threads.poll()) != null) {
            currentThread.join();
        }
    }

    @Test
    @Timeout(value = 10, unit = TimeUnit.SECONDS)
    void testNotSuspendedUntilScheduledTaskIsCancelled() throws Exception {
        TestThreadFactory threadFactory = new TestThreadFactory();
        final SingleThreadEventExecutor executor = new SuspendingSingleThreadEventExecutor(threadFactory);

        // Schedule a task which is so far in the future that we are sure it will not run at all.
        Future<?> future = executor.schedule(() -> { }, 1, TimeUnit.DAYS);
        TestThread currentThread = threadFactory.threads.take();
        // Let's wait until the thread is started
        currentThread.awaitStarted();
        currentThread.awaitRunnableExecution();
        assertTrue(executor.trySuspend());

        // Now cancel the task which should allow the suspension to let the thread die once we call trySuspend() again
        assertTrue(future.cancel(false));
        future.await();

        // Call in a loop as removal of scheduled tasks from task queue might be lazy
        while (!executor.trySuspend()) {