Implement renddezvous sub/unsub test.

This commit is contained in:
Alejandro Cabeza Romero 2024-08-07 21:06:42 +02:00
parent c8bc839c81
commit 788e156800
No known key found for this signature in database
GPG Key ID: DA3D14AE478030FD
1 changed files with 34 additions and 1 deletions

View File

@ -18,7 +18,7 @@ import
discovery/discoverymngr,
discovery/rendezvousinterface,
]
import ./helpers, ./asyncunit
import ./helpers, ./asyncunit, ./utils/async, ./utils/assertions
proc createSwitch(rdv: RendezVous = RendezVous.new()): Switch =
SwitchBuilder
@ -78,3 +78,36 @@ suite "Discovery":
res[PeerId] == clientB.peerInfo.peerId
res.getAll(PeerId) == @[clientB.peerInfo.peerId]
toHashSet(res.getAll(MultiAddress)) == toHashSet(clientB.peerInfo.addrs)
asyncTest "Subscribe and unsubscribe":
dmB.advertise(rdvNamespace)
let
query1 = dmA.request(rdvNamespace)
res1 = await query1.getPeer().waitForResult(1.seconds)
res1.assertIsOk()
check res1.value{PeerId}.get() == clientB.peerInfo.peerId
await rdvB.unsubscribe(namespace)
var
query2 = dmA.request(rdvNamespace)
res2 = await query2.getPeer().waitForResult(1.seconds)
res2.assertIsErr()
asyncTest "Frequent sub/desub":
for i in 0 ..< 10:
dmB.advertise(rdvNamespace)
let
query1 = dmA.request(rdvNamespace)
res1 = await query1.getPeer().waitForResult(1.seconds)
res1.assertIsOk()
check res1.value{PeerId}.get() == clientB.peerInfo.peerId
await rdvB.unsubscribe(namespace)
var
query2 = dmA.request(rdvNamespace)
res2 = await query2.getPeer().waitForResult(1.seconds)
res2.assertIsErr()