Skip to content

Commit

Permalink
Make isolated execute on async testing eventloop actually run (#3116)
Browse files Browse the repository at this point in the history
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 <gbarnett@apple.com>
  • Loading branch information
Lukasa and glbrntt authored Feb 18, 2025
1 parent 42bea78 commit f46998c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Sources/NIOEmbedded/AsyncTestingEventLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion Tests/NIOPosixTests/EventLoopFutureIsolatedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f46998c

Please sign in to comment.