From 37e7a33de45bac894c0b08b56a2f755ebe4884e6 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Thu, 25 Nov 2021 10:04:25 +0000 Subject: [PATCH] Fix testSchedulingTaskOnSleepingLoopWakesUpOnce (#1992) Motivation: This test is flaky, and has always been flaky. The issue here is simply a timing one. It has always been possible for the thread running in the background DispatchQueue to be take longer between calling semaphore.signal and promise.cascade(to:) than it does for the event loop to process the tasks. If that happens, this test will fail by eventually timing out. Modifications: - Adjust the test to avoid using promise.cascade(to:), and so prevent it from having at timing window. Result: The test will be not flaky, or at least less flaky. Resolves #1971. Co-authored-by: George Barnett --- Tests/NIOPosixTests/SALEventLoopTests.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tests/NIOPosixTests/SALEventLoopTests.swift b/Tests/NIOPosixTests/SALEventLoopTests.swift index 56f653d349..8f6df2db1a 100644 --- a/Tests/NIOPosixTests/SALEventLoopTests.swift +++ b/Tests/NIOPosixTests/SALEventLoopTests.swift @@ -66,12 +66,13 @@ final class SALEventLoopTests: XCTestCase, SALTest { } // Now enqueue a "last" task. - let lastTask = thisLoop.submit { i &+= 1 } + thisLoop.execute { + i &+= 1 + promise.succeed(()) + } // Now we can unblock the semaphore. semaphore.signal() - - lastTask.cascade(to: promise) } return promise.futureResult