@@ -201,10 +201,54 @@ suite "test suite for subscribe":
201201 await sleepAsync 500
202202 await ctxMain.publish (" test/random1" , msg, 0 )
203203 await ctxMain.publish (" second/random2" , msg, 0 )
204+ await ctxMain.publish (" test" , msg, 0 )
204205 await ctxMain.publish (" test/random3" , msg, 0 )
205206 await sleepAsync 500
206207 await ctxListen.unsubscribe (" test/#" )
207208 await sleepAsync 500
209+ check (msgCount == 3 )
210+
211+ waitFor conn ()
212+
213+ test " subscribe to test/+" :
214+ let (_, msg) = tdata (" subscribe to test/+" )
215+
216+ proc conn () {.async .} =
217+ var msgCount: int
218+ proc on_data_sub_wild (topic: string , message: string ) =
219+ msgCount += 1
220+
221+ await ctxListen.subscribe (" test/+" , 0 , on_data_sub_wild)
222+ await sleepAsync 500
223+ await ctxMain.publish (" test/random1" , msg, 0 )
224+ await ctxMain.publish (" second/random2" , msg, 0 )
225+ await ctxMain.publish (" test" , msg, 0 )
226+ await ctxMain.publish (" test/random3" , msg, 0 )
227+ await sleepAsync 500
228+ await ctxListen.unsubscribe (" test/+" )
229+ await sleepAsync 500
230+ check (msgCount == 2 )
231+
232+ waitFor conn ()
233+
234+ test " subscribe to test/+/test" :
235+ let (_, msg) = tdata (" subscribe to test/+/test" )
236+
237+ proc conn () {.async .} =
238+ var msgCount: int
239+ proc on_data_sub_wild (topic: string , message: string ) =
240+ msgCount += 1
241+
242+ await ctxListen.subscribe (" test/+/data" , 0 , on_data_sub_wild)
243+ await sleepAsync 500
244+ await ctxMain.publish (" test/random1/data" , msg, 0 )
245+ await ctxMain.publish (" second/random2/data" , msg, 0 )
246+ await ctxMain.publish (" test/random3" , msg, 0 )
247+ await ctxMain.publish (" test/random4/data" , msg, 0 )
248+ await ctxMain.publish (" test/random5/data/random6" , msg, 0 )
249+ await sleepAsync 500
250+ await ctxListen.unsubscribe (" test/+/data" )
251+ await sleepAsync 500
208252 check (msgCount == 2 )
209253
210254 waitFor conn ()
0 commit comments