From f46998ce2d260224a84972c2a17ea3a75ce0c6e3 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Tue, 18 Feb 2025 19:03:24 +0000 Subject: [PATCH] Make isolated execute on async testing eventloop actually run (#3116) Motivation: The isolated execute on async testing event loop wouldn't execute tasks in the case of promise being nil Modifications: Rewrite the execute logic slightly. Result: Correct execution Co-authored-by: George Barnett --- Sources/NIOEmbedded/AsyncTestingEventLoop.swift | 3 ++- Tests/NIOPosixTests/EventLoopFutureIsolatedTests.swift | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/NIOEmbedded/AsyncTestingEventLoop.swift b/Sources/NIOEmbedded/AsyncTestingEventLoop.swift index ef0070b1c..d7101cdb4 100644 --- a/Sources/NIOEmbedded/AsyncTestingEventLoop.swift +++ b/Sources/NIOEmbedded/AsyncTestingEventLoop.swift @@ -146,7 +146,8 @@ public final class NIOAsyncTestingEventLoop: EventLoop, @unchecked Sendable { task: { do { // UnsafeUnchecked is acceptable because we know we're in the loop here. - promise?.assumeIsolatedUnsafeUnchecked().succeed(try task()) + let result = try task() + promise?.assumeIsolatedUnsafeUnchecked().succeed(result) } catch let err { promise?.fail(err) } diff --git a/Tests/NIOPosixTests/EventLoopFutureIsolatedTests.swift b/Tests/NIOPosixTests/EventLoopFutureIsolatedTests.swift index 4b2ec8874..b856ec5f5 100644 --- a/Tests/NIOPosixTests/EventLoopFutureIsolatedTests.swift +++ b/Tests/NIOPosixTests/EventLoopFutureIsolatedTests.swift @@ -331,13 +331,15 @@ final class EventLoopFutureIsolatedTest: XCTestCase { func _eventLoopIsolated(loop: any EventLoop) throws { let f = loop.flatSubmit { let value = SuperNotSendable() + value.x = 4 // Again, all of these need to close over value. In addition, // many need to return it as well. let isolated = loop.assumeIsolated() XCTAssertIdentical(isolated.nonisolated(), loop) isolated.execute { - XCTAssertEqual(value.x, 5) + XCTAssertEqual(value.x, 4) + value.x = 5 } let firstFuture = isolated.submit { let val = SuperNotSendable()