Skip to content

Commit

Permalink
Implement renddezvous sub/unsub test.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroCabeza committed Aug 7, 2024
1 parent 38ad5f1 commit 5063cab
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tests/testdiscovery.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 5063cab

Please sign in to comment.