-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TaskExecutor conformance to EventLoops
- Loading branch information
1 parent
9f63b12
commit a982359
Showing
4 changed files
with
99 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftNIO open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
import NIOCore | ||
import NIOEmbedded | ||
import NIOPosix | ||
import XCTest | ||
|
||
final class TaskExecutorTests: XCTestCase { | ||
@available(macOS 9999.0, iOS 9999.0, watchOS 9999.0, tvOS 9999.0, *) | ||
func testBasicExecutorFitsOnEventLoop_MTELG() async throws { | ||
#if compiler(>=6.0) | ||
let group = MultiThreadedEventLoopGroup(numberOfThreads: 2) | ||
defer { | ||
try! group.syncShutdownGracefully() | ||
} | ||
let loops = Array(group.makeIterator()) | ||
await withTaskGroup(of: Void.self) { taskGroup in | ||
taskGroup.addTask(executorPreference: loops[0].taskExecutor) { | ||
loops[0].assertInEventLoop() | ||
loops[1].assertNotInEventLoop() | ||
|
||
withUnsafeCurrentTask { task in | ||
// this currently fails on macOS | ||
XCTAssertEqual(task?.unownedTaskExecutor, loops[0].taskExecutor.asUnownedTaskExecutor()) | ||
} | ||
} | ||
|
||
taskGroup.addTask(executorPreference: loops[1].taskExecutor) { | ||
loops[0].assertNotInEventLoop() | ||
loops[1].assertInEventLoop() | ||
|
||
withUnsafeCurrentTask { task in | ||
// this currently fails on macOS | ||
XCTAssertEqual(task?.unownedTaskExecutor, loops[1].taskExecutor.asUnownedTaskExecutor()) | ||
} | ||
} | ||
} | ||
#endif | ||
} | ||
} |