@@ -5,104 +5,90 @@ suite "test suite for connections":
55 let (tpc, msg) = tdata (" connection public broker" )
66
77 proc conn () {.async .} =
8- let ctx = newMqttCtx (" nmqttTestConn" )
9- ctx.set_host ( " test.mosquitto.org " , 1883 )
8+ let ctx = newMqttCtx (" nmqttTestConn" & tpc) # unique clientid for public broker
9+ ctx.setHost ( " broker-cn.emqx.io " , 1883 )
1010 await ctx.connect ()
1111 await sleepAsync (1500 )
1212 check (ctx.state == Connected )
1313 await ctx.publish (tpc, msg, 0 )
1414 await sleepAsync (1500 )
1515 await ctx.disconnect ()
1616 check (ctx.state == Disabled )
17- waitFor conn ()
1817
18+ waitFor conn ()
1919
2020 test " connection public broker SSL" :
2121 let (tpc, msg) = tdata (" connection public broker SSL" )
2222
2323 proc conn () {.async .} =
24- let ctx = newMqttCtx (" nmqttTestConn" )
25- ctx.set_host ( " test.mosquitto.org " , 8883 , true )
24+ let ctx = newMqttCtx (" nmqttTestConn" & tpc) # unique clientid for public broker
25+ ctx.setHost ( " broker-cn.emqx.io " , 8883 , true )
2626 await ctx.connect ()
2727 await sleepAsync (1500 )
2828 check (ctx.state == Connected )
2929 await ctx.publish (tpc, msg, 0 )
3030 await sleepAsync (1500 )
3131 await ctx.disconnect ()
3232 check (ctx.state == Disabled )
33- waitFor conn ()
34-
35-
36- #[ test "connection wrong port - timeout":
37- proc conn() {.async.} =
38- let ctx = newMqttCtx("nmqttTestConn")
39- ctx.set_host("test.mosquitto.org", 2222)
40- await ctx.start()
41- check(ctx.state == Error)
42- waitFor conn()]#
4333
34+ waitFor conn ()
4435
4536 test " connect() to broker" :
46- # # FAILS. Due to `runConnect` it will reconnect forever
37+ let ctxMain = newCtx ()
4738
4839 proc conn () {.async .} =
49- await ctxSlave .connect ()
40+ await ctxMain .connect ()
5041 await sleepAsync (500 )
51- check (ctxSlave .state == Connected )
42+ check (ctxMain .state == Connected )
5243
5344 # Do important stuff
5445 await sleepAsync (500 )
5546
5647 # Disconnect
57- await ctxSlave .disconnect ()
58- check (ctxSlave .state == Disabled )
48+ await ctxMain .disconnect ()
49+ check (ctxMain .state == Disabled )
5950
6051 waitFor conn ()
6152
62-
6353 test " start() and reconnect" :
64- # # FAILS. Due to `runConnect` it will reconnect forever
54+ let ctxMain = newCtx ()
6555
6656 proc conn () {.async .} =
6757 await sleepAsync (500 )
68- await ctxSlave.start ()
69- await sleepAsync (500 )
70- check (ctxSlave.state == Connected )
58+ check (ctxMain.state == Connected )
7159
7260 # Do important stuff
7361 await sleepAsync (500 )
7462
7563 # Close connection
76- ctxSlave.state = Disconnecting
77- ctxSlave.s.close ()
78- echo (ctxSlave.state) # = Disconnected
64+ ctxMain.state = Disconnecting
65+ ctxMain.s.close ()
7966 await sleepAsync (500 )
8067
8168 # Auto-reconnect goes on `Disconnected"
82- ctxSlave .state = Disconnected
69+ ctxMain .state = Disconnected
8370 # Auto-reconnect loop is 1000ms, wait 2000ms to ensure loop
8471 await sleepAsync (2000 )
8572
8673 # Check reconnect
87- check (ctxSlave .state == Connected )
74+ check (ctxMain .state == Connected )
8875
8976 # Disconnect
90- await ctxSlave .disconnect ()
91- check (ctxSlave .state == Disabled )
77+ await ctxMain .disconnect ()
78+ check (ctxMain .state == Disabled )
9279
9380 waitFor conn ()
9481
95-
9682 test " isConnected()" :
97- # # FAILS. Due to `runConnect` it will reconnect forever
83+ let ctxMain = newCtx ()
9884
9985 proc conn () {.async .} =
100- check (ctxSlave .isConnected () == false )
101- await ctxSlave .connect ()
86+ check (ctxMain .isConnected () == false )
87+ await ctxMain .connect ()
10288 await sleepAsync (500 )
103- check (ctxSlave .isConnected () == true )
89+ check (ctxMain .isConnected () == true )
10490
105- await ctxSlave .disconnect ()
106- check (ctxSlave .state == Disabled )
91+ await ctxMain .disconnect ()
92+ check (ctxMain .state == Disabled )
10793
108- waitFor conn ()
94+ waitFor conn ()
0 commit comments