From a26c6dc55c10afcf6cb4f0c5b4406cd2f01d0d05 Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Mon, 9 Sep 2024 19:07:17 +0100 Subject: [PATCH] Speculative fix for flakey AsyncTestingEventLoop test (#2873) ### Motivation: We're seeing some very rare failures from this test in CI runs but I cannot reproduce locally. The test relies on timing to some degree and the interaction of scheduling tasks at shutdown. ### Modifications: The `AsyncTestingEventLoop` has an `executeInContext` function which puts the closure on the backing dispatch queue and blocks. In this instance it might be a good way to make sure that all the previous work has happened. ### Result: (Hopefully) less flakey test. --- Tests/NIOEmbeddedTests/AsyncTestingEventLoopTests.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/NIOEmbeddedTests/AsyncTestingEventLoopTests.swift b/Tests/NIOEmbeddedTests/AsyncTestingEventLoopTests.swift index 9b7499cbae..08cee06cb4 100644 --- a/Tests/NIOEmbeddedTests/AsyncTestingEventLoopTests.swift +++ b/Tests/NIOEmbeddedTests/AsyncTestingEventLoopTests.swift @@ -507,7 +507,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase { try await group.waitForAll() } - XCTAssertGreaterThan(tasksRun.load(ordering: .acquiring), 1) + try await eventLoop.executeInContext { + XCTAssertGreaterThan(tasksRun.load(ordering: .acquiring), 1) + } } func testShutdownCancelsRemainingScheduledTasks() async {