@@ -12,12 +12,12 @@ final class MQTTNIOTests: XCTestCase {
12
12
static let hostname = ProcessInfo . processInfo. environment [ " MOSQUITTO_SERVER " ] ?? " localhost "
13
13
14
14
func connect( to client: MQTTClient ) throws {
15
- try client. connect ( ) . wait ( )
15
+ _ = try client. connect ( ) . wait ( )
16
16
}
17
17
18
18
func testConnectWithWill( ) throws {
19
19
let client = createClient ( identifier: " testConnectWithWill " )
20
- try client. connect (
20
+ _ = try client. connect (
21
21
will: ( topicName: " MyWillTopic " , payload: ByteBufferAllocator ( ) . buffer ( string: " Test payload " ) , retain: false )
22
22
) . wait ( )
23
23
try client. ping ( ) . wait ( )
@@ -27,63 +27,63 @@ final class MQTTNIOTests: XCTestCase {
27
27
28
28
func testWebsocketConnect( ) throws {
29
29
let client = createWebSocketClient ( identifier: " testWebsocketConnect " )
30
- try client. connect ( ) . wait ( )
30
+ _ = try client. connect ( ) . wait ( )
31
31
try client. ping ( ) . wait ( )
32
32
try client. disconnect ( ) . wait ( )
33
33
try client. syncShutdownGracefully ( )
34
34
}
35
35
36
36
func testSSLConnect( ) throws {
37
37
let client = try createSSLClient ( identifier: " testSSLConnect " )
38
- try client. connect ( ) . wait ( )
38
+ _ = try client. connect ( ) . wait ( )
39
39
try client. ping ( ) . wait ( )
40
40
try client. disconnect ( ) . wait ( )
41
41
try client. syncShutdownGracefully ( )
42
42
}
43
43
44
44
func testWebsocketAndSSLConnect( ) throws {
45
45
let client = try createWebSocketAndSSLClient ( identifier: " testWebsocketAndSSLConnect " )
46
- try client. connect ( ) . wait ( )
46
+ _ = try client. connect ( ) . wait ( )
47
47
try client. ping ( ) . wait ( )
48
48
try client. disconnect ( ) . wait ( )
49
49
try client. syncShutdownGracefully ( )
50
50
}
51
51
52
52
func testMQTTPublishQoS0( ) throws {
53
53
let client = self . createClient ( identifier: " testMQTTPublishQoS0 " )
54
- try client. connect ( ) . wait ( )
54
+ _ = try client. connect ( ) . wait ( )
55
55
try client. publish ( to: " testMQTTPublishQoS " , payload: ByteBufferAllocator ( ) . buffer ( string: " Test payload " ) , qos: . atMostOnce) . wait ( )
56
56
try client. disconnect ( ) . wait ( )
57
57
try client. syncShutdownGracefully ( )
58
58
}
59
59
60
60
func testMQTTPublishQoS1( ) throws {
61
61
let client = try self . createSSLClient ( identifier: " testMQTTPublishQoS1 " )
62
- try client. connect ( ) . wait ( )
62
+ _ = try client. connect ( ) . wait ( )
63
63
try client. publish ( to: " testMQTTPublishQoS " , payload: ByteBufferAllocator ( ) . buffer ( string: " Test payload " ) , qos: . atLeastOnce) . wait ( )
64
64
try client. disconnect ( ) . wait ( )
65
65
try client. syncShutdownGracefully ( )
66
66
}
67
67
68
68
func testMQTTPublishQoS2( ) throws {
69
69
let client = try self . createWebSocketAndSSLClient ( identifier: " testMQTTPublishQoS2 " )
70
- try client. connect ( ) . wait ( )
70
+ _ = try client. connect ( ) . wait ( )
71
71
try client. publish ( to: " testMQTTPublishQoS " , payload: ByteBufferAllocator ( ) . buffer ( string: " Test payload " ) , qos: . exactlyOnce) . wait ( )
72
72
try client. disconnect ( ) . wait ( )
73
73
try client. syncShutdownGracefully ( )
74
74
}
75
75
76
76
func testMQTTPingreq( ) throws {
77
77
let client = self . createClient ( identifier: " testMQTTPingreq " )
78
- try client. connect ( ) . wait ( )
78
+ _ = try client. connect ( ) . wait ( )
79
79
try client. ping ( ) . wait ( )
80
80
try client. disconnect ( ) . wait ( )
81
81
try client. syncShutdownGracefully ( )
82
82
}
83
83
84
84
func testMQTTSubscribe( ) throws {
85
85
let client = self . createClient ( identifier: " testMQTTSubscribe " )
86
- try client. connect ( ) . wait ( )
86
+ _ = try client. connect ( ) . wait ( )
87
87
try client. subscribe ( to: [ . init( topicFilter: " iphone " , qos: . atLeastOnce) ] ) . wait ( )
88
88
Thread . sleep ( forTimeInterval: 5 )
89
89
try client. disconnect ( ) . wait ( )
@@ -103,7 +103,7 @@ final class MQTTNIOTests: XCTestCase {
103
103
}
104
104
105
105
let client = self . createClient ( identifier: " testMQTTServerDisconnect " )
106
- try client. connect ( ) . wait ( )
106
+ _ = try client. connect ( ) . wait ( )
107
107
try client. connection? . sendMessageNoWait ( MQTTForceDisconnectMessage ( ) ) . wait ( )
108
108
Thread . sleep ( forTimeInterval: 2 )
109
109
XCTAssertFalse ( client. isActive ( ) )
@@ -117,7 +117,7 @@ final class MQTTNIOTests: XCTestCase {
117
117
let payload = ByteBufferAllocator ( ) . buffer ( string: payloadString)
118
118
119
119
let client = self . createWebSocketClient ( identifier: " testMQTTPublishToClient_publisher " )
120
- try client. connect ( ) . wait ( )
120
+ _ = try client. connect ( ) . wait ( )
121
121
let client2 = self . createWebSocketClient ( identifier: " testMQTTPublishToClient_subscriber " )
122
122
client2. addPublishListener ( named: " test " ) { result in
123
123
switch result {
@@ -132,7 +132,7 @@ final class MQTTNIOTests: XCTestCase {
132
132
XCTFail ( " \( error) " )
133
133
}
134
134
}
135
- try client2. connect ( ) . wait ( )
135
+ _ = try client2. connect ( ) . wait ( )
136
136
try client2. subscribe ( to: [ . init( topicFilter: " testMQTTAtLeastOnce " , qos: . atLeastOnce) ] ) . wait ( )
137
137
try client2. subscribe ( to: [ . init( topicFilter: " testMQTTExactlyOnce " , qos: . exactlyOnce) ] ) . wait ( )
138
138
try client. publish ( to: " testMQTTAtLeastOnce " , payload: payload, qos: . atLeastOnce) . wait ( )
@@ -154,7 +154,7 @@ final class MQTTNIOTests: XCTestCase {
154
154
let payload = ByteBufferAllocator ( ) . buffer ( string: payloadString)
155
155
156
156
let client = self . createClient ( identifier: " testUnsubscribe_publisher " )
157
- try client. connect ( ) . wait ( )
157
+ _ = try client. connect ( ) . wait ( )
158
158
let client2 = self . createClient ( identifier: " testUnsubscribe_subscriber " )
159
159
client2. addPublishListener ( named: " test " ) { result in
160
160
switch result {
@@ -169,7 +169,7 @@ final class MQTTNIOTests: XCTestCase {
169
169
XCTFail ( " \( error) " )
170
170
}
171
171
}
172
- try client2. connect ( ) . wait ( )
172
+ _ = try client2. connect ( ) . wait ( )
173
173
try client2. subscribe ( to: [ . init( topicFilter: " testUnsubscribe " , qos: . atLeastOnce) ] ) . wait ( )
174
174
try client. publish ( to: " testUnsubscribe " , payload: payload, qos: . atLeastOnce) . wait ( )
175
175
try client2. unsubscribe ( from: [ " testUnsubscribe " ] ) . wait ( )
@@ -192,7 +192,7 @@ final class MQTTNIOTests: XCTestCase {
192
192
let payload = ByteBufferAllocator ( ) . buffer ( data: payloadData)
193
193
194
194
let client = self . createWebSocketClient ( identifier: " testMQTTPublishToClientLargePayload_publisher " )
195
- try client. connect ( ) . wait ( )
195
+ _ = try client. connect ( ) . wait ( )
196
196
let client2 = self . createWebSocketClient ( identifier: " testMQTTPublishToClientLargePayload_subscriber " )
197
197
client2. addPublishListener ( named: " test " ) { result in
198
198
switch result {
@@ -207,7 +207,7 @@ final class MQTTNIOTests: XCTestCase {
207
207
XCTFail ( " \( error) " )
208
208
}
209
209
}
210
- try client2. connect ( ) . wait ( )
210
+ _ = try client2. connect ( ) . wait ( )
211
211
try client2. subscribe ( to: [ . init( topicFilter: " testMQTTAtLeastOnce " , qos: . atLeastOnce) ] ) . wait ( )
212
212
try client. publish ( to: " testMQTTAtLeastOnce " , payload: payload, qos: . atLeastOnce) . wait ( )
213
213
Thread . sleep ( forTimeInterval: 2 )
@@ -234,9 +234,9 @@ final class MQTTNIOTests: XCTestCase {
234
234
}
235
235
}
236
236
237
- try client. connect ( ) . wait ( )
237
+ _ = try client. connect ( ) . wait ( )
238
238
// by connecting with same identifier the first client uses the first client is forced to disconnect
239
- try client2. connect ( ) . wait ( )
239
+ _ = try client2. connect ( ) . wait ( )
240
240
241
241
Thread . sleep ( forTimeInterval: 5 )
242
242
XCTAssertTrue ( disconnected. load ( ) )
@@ -248,8 +248,11 @@ final class MQTTNIOTests: XCTestCase {
248
248
249
249
func testDoubleConnect( ) throws {
250
250
let client = self . createClient ( identifier: " DoubleConnect " )
251
- try client. connect ( cleanSession: true ) . wait ( )
252
- try client. connect ( cleanSession: false ) . wait ( )
251
+ _ = try client. connect ( cleanSession: true ) . wait ( )
252
+ let sessionPresent = try client. connect ( cleanSession: false ) . wait ( )
253
+ let sessionPresent2 = try client. connect ( cleanSession: false ) . wait ( )
254
+ XCTAssertFalse ( sessionPresent)
255
+ XCTAssertTrue ( sessionPresent2)
253
256
try client. disconnect ( ) . wait ( )
254
257
try client. syncShutdownGracefully ( )
255
258
}
@@ -262,7 +265,7 @@ final class MQTTNIOTests: XCTestCase {
262
265
return nil
263
266
}
264
267
let client = self . createClient ( identifier: " testMQTTPublishQoS2WithStall " , timeout: . seconds( 4 ) )
265
- try client. connect ( ) . wait ( )
268
+ _ = try client. connect ( ) . wait ( )
266
269
try client. connection? . channel. pipeline. addHandler ( stallHandler) . wait ( )
267
270
try client. publish ( to: " testMQTTPublishQoS2WithStall " , payload: ByteBufferAllocator ( ) . buffer ( string: " Test payload " ) , qos: . exactlyOnce) . wait ( )
268
271
try client. disconnect ( ) . wait ( )
@@ -281,7 +284,7 @@ final class MQTTNIOTests: XCTestCase {
281
284
let payload = ByteBufferAllocator ( ) . buffer ( string: " This is the Test payload " )
282
285
283
286
let client = self . createClient ( identifier: " testMQTTPublishToClient_publisher " , timeout: . seconds( 2 ) )
284
- try client. connect ( ) . wait ( )
287
+ _ = try client. connect ( ) . wait ( )
285
288
let client2 = self . createClient ( identifier: " testMQTTPublishToClient_subscriber " , timeout: . seconds( 10 ) )
286
289
client2. addPublishListener ( named: " test " ) { result in
287
290
switch result {
@@ -297,7 +300,7 @@ final class MQTTNIOTests: XCTestCase {
297
300
XCTFail ( " \( error) " )
298
301
}
299
302
}
300
- try client2. connect ( ) . wait ( )
303
+ _ = try client2. connect ( ) . wait ( )
301
304
try client2. connection? . channel. pipeline. addHandler ( stallHandler, position: . first) . wait ( )
302
305
try client2. subscribe ( to: [ . init( topicFilter: " testMQTTSubscribeQoS2WithStall " , qos: . exactlyOnce) ] ) . wait ( )
303
306
try client. publish ( to: " testMQTTSubscribeQoS2WithStall " , payload: payload, qos: . exactlyOnce) . wait ( )
@@ -319,7 +322,7 @@ final class MQTTNIOTests: XCTestCase {
319
322
let payload = ByteBufferAllocator ( ) . buffer ( string: payloadString)
320
323
321
324
let client = try self . createSSLClient ( identifier: " testPersistentSession_publisher " )
322
- try client. connect ( ) . wait ( )
325
+ _ = try client. connect ( ) . wait ( )
323
326
let client2 = try self . createSSLClient ( identifier: " testPersistentSession_subscriber " )
324
327
client2. addPublishListener ( named: " test " ) { result in
325
328
switch result {
@@ -334,22 +337,22 @@ final class MQTTNIOTests: XCTestCase {
334
337
XCTFail ( " \( error) " )
335
338
}
336
339
}
337
- try client2. connect ( cleanSession: true ) . wait ( )
338
- try client2. connect ( cleanSession: false ) . wait ( )
340
+ _ = try client2. connect ( cleanSession: true ) . wait ( )
341
+ _ = try client2. connect ( cleanSession: false ) . wait ( )
339
342
try client2. subscribe ( to: [ . init( topicFilter: " testMQTTAtLeastOnce " , qos: . atLeastOnce) ] ) . wait ( )
340
343
try client. publish ( to: " testMQTTAtLeastOnce " , payload: payload, qos: . atLeastOnce) . wait ( )
341
344
Thread . sleep ( forTimeInterval: 1 )
342
345
try client2. disconnect ( ) . wait ( )
343
346
try client. publish ( to: " testMQTTAtLeastOnce " , payload: payload, qos: . atLeastOnce) . wait ( )
344
347
Thread . sleep ( forTimeInterval: 1 )
345
348
// should receive previous publish on new connect as this is not a cleanSession
346
- try client2. connect ( cleanSession: false ) . wait ( )
349
+ _ = try client2. connect ( cleanSession: false ) . wait ( )
347
350
Thread . sleep ( forTimeInterval: 1 )
348
351
try client2. disconnect ( ) . wait ( )
349
352
Thread . sleep ( forTimeInterval: 1 )
350
353
try client. publish ( to: " testMQTTAtLeastOnce " , payload: payload, qos: . atLeastOnce) . wait ( )
351
354
// should not receive previous publish on connect as this is a cleanSession
352
- try client2. connect ( cleanSession: true ) . wait ( )
355
+ _ = try client2. connect ( cleanSession: true ) . wait ( )
353
356
Thread . sleep ( forTimeInterval: 1 )
354
357
lock. withLock {
355
358
XCTAssertEqual ( publishReceived. count, 2 )
0 commit comments