@@ -17,32 +17,89 @@ import NIOPosix
1717import XCTest
1818
1919final class TaskExecutorTests : XCTestCase {
20+
21+ #if compiler(>=6.0)
2022 @available ( macOS 9999 . 0 , iOS 9999 . 0 , watchOS 9999 . 0 , tvOS 9999 . 0 , * )
21- func testBasicExecutorFitsOnEventLoop_MTELG( ) async throws {
23+ func _runTests( loop1: some EventLoop , loop2: some EventLoop ) async {
24+ await withTaskGroup ( of: Void . self) { taskGroup in
25+ taskGroup. addTask ( executorPreference: loop1. taskExecutor) {
26+ loop1. assertInEventLoop ( )
27+ loop2. assertNotInEventLoop ( )
28+
29+ withUnsafeCurrentTask { task in
30+ // this currently fails on macOS
31+ XCTAssertEqual ( task? . unownedTaskExecutor, loop1. taskExecutor. asUnownedTaskExecutor ( ) )
32+ }
33+ }
34+
35+ taskGroup. addTask ( executorPreference: loop2. taskExecutor) {
36+ loop1. assertNotInEventLoop ( )
37+ loop2. assertInEventLoop ( )
38+
39+ withUnsafeCurrentTask { task in
40+ // this currently fails on macOS
41+ XCTAssertEqual ( task? . unownedTaskExecutor, loop2. taskExecutor. asUnownedTaskExecutor ( ) )
42+ }
43+ }
44+ }
45+
46+ let task = Task ( executorPreference: loop1. taskExecutor) {
47+ loop1. assertInEventLoop ( )
48+ loop2. assertNotInEventLoop ( )
49+
50+ withUnsafeCurrentTask { task in
51+ // this currently fails on macOS
52+ XCTAssertEqual ( task? . unownedTaskExecutor, loop1. taskExecutor. asUnownedTaskExecutor ( ) )
53+ }
54+ }
55+
56+ await task. value
57+ }
58+ #endif
59+
60+ @available ( macOS 9999 . 0 , iOS 9999 . 0 , watchOS 9999 . 0 , tvOS 9999 . 0 , * )
61+ func testSelectableEventLoopAsTaskExecutor( ) async throws {
2262 #if compiler(>=6.0)
2363 let group = MultiThreadedEventLoopGroup ( numberOfThreads: 2 )
2464 defer {
2565 try ! group. syncShutdownGracefully ( )
2666 }
27- let loops = Array ( group. makeIterator ( ) )
67+ var iterator = group. makeIterator ( )
68+ let loop1 = iterator. next ( ) !
69+ let loop2 = iterator. next ( ) !
70+
71+ await self . _runTests ( loop1: loop1, loop2: loop2)
72+ #endif
73+ }
74+
75+ @available ( macOS 9999 . 0 , iOS 9999 . 0 , watchOS 9999 . 0 , tvOS 9999 . 0 , * )
76+ func testAsyncTestingEventLoopAsTaskExecutor( ) async throws {
77+ #if compiler(>=6.0)
78+ let loop1 = NIOAsyncTestingEventLoop ( )
79+ let loop2 = NIOAsyncTestingEventLoop ( )
80+ defer {
81+ try ? loop1. syncShutdownGracefully ( )
82+ try ? loop2. syncShutdownGracefully ( )
83+ }
84+
2885 await withTaskGroup ( of: Void . self) { taskGroup in
29- taskGroup. addTask ( executorPreference: loops [ 0 ] . taskExecutor) {
30- loops [ 0 ] . assertInEventLoop ( )
31- loops [ 1 ] . assertNotInEventLoop ( )
86+ taskGroup. addTask ( executorPreference: loop1 . taskExecutor) {
87+ loop1 . assertInEventLoop ( )
88+ loop2 . assertNotInEventLoop ( )
3289
3390 withUnsafeCurrentTask { task in
3491 // this currently fails on macOS
35- XCTAssertEqual ( task? . unownedTaskExecutor, loops [ 0 ] . taskExecutor. asUnownedTaskExecutor ( ) )
92+ XCTAssertEqual ( task? . unownedTaskExecutor, loop1 . taskExecutor. asUnownedTaskExecutor ( ) )
3693 }
3794 }
3895
39- taskGroup. addTask ( executorPreference: loops [ 1 ] . taskExecutor ) {
40- loops [ 0 ] . assertNotInEventLoop ( )
41- loops [ 1 ] . assertInEventLoop ( )
96+ taskGroup. addTask ( executorPreference: loop2 ) {
97+ loop1 . assertNotInEventLoop ( )
98+ loop2 . assertInEventLoop ( )
4299
43100 withUnsafeCurrentTask { task in
44101 // this currently fails on macOS
45- XCTAssertEqual ( task? . unownedTaskExecutor, loops [ 1 ] . taskExecutor. asUnownedTaskExecutor ( ) )
102+ XCTAssertEqual ( task? . unownedTaskExecutor, loop2 . taskExecutor. asUnownedTaskExecutor ( ) )
46103 }
47104 }
48105 }
0 commit comments