@@ -10,6 +10,7 @@ class GraphqlTransportWSTests: XCTestCase {
10
10
var clientMessenger : TestMessenger !
11
11
var serverMessenger : TestMessenger !
12
12
var server : Server < TokenInitPayload > !
13
+ var eventLoop : EventLoop !
13
14
14
15
override func setUp( ) {
15
16
// Point the client and server at each other
@@ -18,7 +19,7 @@ class GraphqlTransportWSTests: XCTestCase {
18
19
clientMessenger. other = serverMessenger
19
20
serverMessenger. other = clientMessenger
20
21
21
- let eventLoop = MultiThreadedEventLoopGroup ( numberOfThreads: 1 ) . next ( )
22
+ eventLoop = MultiThreadedEventLoopGroup ( numberOfThreads: 1 ) . next ( )
22
23
let api = TestAPI ( )
23
24
let context = TestContext ( )
24
25
@@ -28,16 +29,17 @@ class GraphqlTransportWSTests: XCTestCase {
28
29
api. execute (
29
30
request: graphQLRequest. query,
30
31
context: context,
31
- on: eventLoop
32
+ on: self . eventLoop
32
33
)
33
34
} ,
34
35
onSubscribe: { graphQLRequest in
35
36
api. subscribe (
36
37
request: graphQLRequest. query,
37
38
context: context,
38
- on: eventLoop
39
+ on: self . eventLoop
39
40
)
40
- }
41
+ } ,
42
+ eventLoop: self . eventLoop
41
43
)
42
44
}
43
45
@@ -71,7 +73,7 @@ class GraphqlTransportWSTests: XCTestCase {
71
73
}
72
74
73
75
/// Tests that throwing in the authorization callback forces an unauthorized error
74
- func testAuth ( ) throws {
76
+ func testAuthWithThrow ( ) throws {
75
77
server. auth { payload in
76
78
throw TestError . couldBeAnything
77
79
}
@@ -98,6 +100,34 @@ class GraphqlTransportWSTests: XCTestCase {
98
100
)
99
101
}
100
102
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
+
101
131
/// Tests a single-op conversation
102
132
func testSingleOp( ) throws {
103
133
let id = UUID ( ) . description
0 commit comments