@@ -105,7 +105,7 @@ final class MQTTNIOTests: XCTestCase {
105105 let client = self . createClient ( identifier: " testMQTTServerDisconnect " )
106106 try client. connect ( ) . wait ( )
107107 try client. connection? . sendMessageNoWait ( MQTTForceDisconnectMessage ( ) ) . wait ( )
108- Thread . sleep ( forTimeInterval: 1 )
108+ Thread . sleep ( forTimeInterval: 2 )
109109 XCTAssertFalse ( client. isActive ( ) )
110110 try client. syncShutdownGracefully ( )
111111 }
@@ -246,6 +246,14 @@ final class MQTTNIOTests: XCTestCase {
246246 try client2. syncShutdownGracefully ( )
247247 }
248248
249+ func testDoubleConnect( ) throws {
250+ let client = self . createClient ( identifier: " DoubleConnect " )
251+ try client. connect ( cleanSession: true ) . wait ( )
252+ try client. connect ( cleanSession: false ) . wait ( )
253+ try client. disconnect ( ) . wait ( )
254+ try client. syncShutdownGracefully ( )
255+ }
256+
249257 func testMQTTPublishQoS2WithStall( ) throws {
250258 let stallHandler = OutboundStallHandler { message in
251259 if message. type == . PUBLISH || message. type == . PUBREL {
@@ -330,16 +338,19 @@ final class MQTTNIOTests: XCTestCase {
330338 try client2. connect ( cleanSession: false ) . wait ( )
331339 try client2. subscribe ( to: [ . init( topicFilter: " testMQTTAtLeastOnce " , qos: . atLeastOnce) ] ) . wait ( )
332340 try client. publish ( to: " testMQTTAtLeastOnce " , payload: payload, qos: . atLeastOnce) . wait ( )
341+ Thread . sleep ( forTimeInterval: 1 )
333342 try client2. disconnect ( ) . wait ( )
334343 try client. publish ( to: " testMQTTAtLeastOnce " , payload: payload, qos: . atLeastOnce) . wait ( )
344+ Thread . sleep ( forTimeInterval: 1 )
335345 // should receive previous publish on new connect as this is not a cleanSession
336346 try client2. connect ( cleanSession: false ) . wait ( )
347+ Thread . sleep ( forTimeInterval: 1 )
337348 try client2. disconnect ( ) . wait ( )
349+ Thread . sleep ( forTimeInterval: 1 )
338350 try client. publish ( to: " testMQTTAtLeastOnce " , payload: payload, qos: . atLeastOnce) . wait ( )
339351 // should not receive previous publish on connect as this is a cleanSession
340352 try client2. connect ( cleanSession: true ) . wait ( )
341-
342- Thread . sleep ( forTimeInterval: 2 )
353+ Thread . sleep ( forTimeInterval: 1 )
343354 lock. withLock {
344355 XCTAssertEqual ( publishReceived. count, 2 )
345356 }
0 commit comments