@@ -10,6 +10,7 @@ class GraphqlTransportWSTests: XCTestCase {
1010 var clientMessenger : TestMessenger !
1111 var serverMessenger : TestMessenger !
1212 var server : Server < TokenInitPayload > !
13+ var eventLoop : EventLoop !
1314
1415 override func setUp( ) {
1516 // Point the client and server at each other
@@ -18,7 +19,7 @@ class GraphqlTransportWSTests: XCTestCase {
1819 clientMessenger. other = serverMessenger
1920 serverMessenger. other = clientMessenger
2021
21- let eventLoop = MultiThreadedEventLoopGroup ( numberOfThreads: 1 ) . next ( )
22+ eventLoop = MultiThreadedEventLoopGroup ( numberOfThreads: 1 ) . next ( )
2223 let api = TestAPI ( )
2324 let context = TestContext ( )
2425
@@ -28,16 +29,17 @@ class GraphqlTransportWSTests: XCTestCase {
2829 api. execute (
2930 request: graphQLRequest. query,
3031 context: context,
31- on: eventLoop
32+ on: self . eventLoop
3233 )
3334 } ,
3435 onSubscribe: { graphQLRequest in
3536 api. subscribe (
3637 request: graphQLRequest. query,
3738 context: context,
38- on: eventLoop
39+ on: self . eventLoop
3940 )
40- }
41+ } ,
42+ eventLoop: self . eventLoop
4143 )
4244 }
4345
@@ -71,7 +73,7 @@ class GraphqlTransportWSTests: XCTestCase {
7173 }
7274
7375 /// Tests that throwing in the authorization callback forces an unauthorized error
74- func testAuth ( ) throws {
76+ func testAuthWithThrow ( ) throws {
7577 server. auth { payload in
7678 throw TestError . couldBeAnything
7779 }
@@ -98,6 +100,34 @@ class GraphqlTransportWSTests: XCTestCase {
98100 )
99101 }
100102
103+ /// Tests that failing a future in the authorization callback forces an unauthorized error
104+ func testAuthWithFailedFuture( ) throws {
105+ server. auth { payload in
106+ self . eventLoop. makeFailedFuture ( TestError . couldBeAnything)
107+ }
108+
109+ var messages = [ String] ( )
110+ let completeExpectation = XCTestExpectation ( )
111+
112+ let client = Client < TokenInitPayload > ( messenger: clientMessenger)
113+ client. onMessage { message, _ in
114+ messages. append ( message)
115+ completeExpectation. fulfill ( )
116+ }
117+
118+ client. sendConnectionInit (
119+ payload: TokenInitPayload (
120+ authToken: " "
121+ )
122+ )
123+
124+ wait ( for: [ completeExpectation] , timeout: 2 )
125+ XCTAssertEqual (
126+ messages,
127+ [ " \( ErrorCode . unauthorized) : Unauthorized " ]
128+ )
129+ }
130+
101131 /// Tests a single-op conversation
102132 func testSingleOp( ) throws {
103133 let id = UUID ( ) . description
0 commit comments