mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2025-03-01 16:40:32 +00:00
Add tests
This commit is contained in:
parent
e0fcbcfd61
commit
e95b9e2c60
@ -53,17 +53,15 @@ suite "Autorelay":
|
||||
fut.complete()
|
||||
autorelay = AutoRelayService.new(3, relayClient, checkMA, rng)
|
||||
switchClient = createSwitch(relayClient, autorelay)
|
||||
await switchClient.start()
|
||||
await switchRelay.start()
|
||||
await allFutures(switchClient.start(), switchRelay.start())
|
||||
await switchClient.connect(switchRelay.peerInfo.peerId, switchRelay.peerInfo.addrs)
|
||||
discard autorelay.run(switchClient)
|
||||
await fut
|
||||
echo "ahbahouais"
|
||||
await fut.wait(1.seconds)
|
||||
let addresses = autorelay.getAddresses()
|
||||
check: addresses[0] == buildRelayMA(switchRelay, switchClient)
|
||||
check: addresses.len() == 1
|
||||
await switchClient.stop()
|
||||
await switchRelay.stop()
|
||||
check:
|
||||
addresses[0] == buildRelayMA(switchRelay, switchClient)
|
||||
addresses.len() == 1
|
||||
await allFutures(switchClient.stop(), switchRelay.stop())
|
||||
|
||||
asyncTest "Connect after starting switches":
|
||||
switchRelay = createSwitch(Relay.new())
|
||||
@ -74,11 +72,58 @@ suite "Autorelay":
|
||||
fut.complete()
|
||||
let autorelay = AutoRelayService.new(3, relayClient, checkMA, newRng())
|
||||
switchClient = createSwitch(relayClient, autorelay)
|
||||
await switchClient.start()
|
||||
await switchRelay.start()
|
||||
await allFutures(switchClient.start(), switchRelay.start())
|
||||
discard autorelay.run(switchClient)
|
||||
await sleepAsync(500.millis)
|
||||
await switchClient.connect(switchRelay.peerInfo.peerId, switchRelay.peerInfo.addrs)
|
||||
await fut.wait(1.seconds)
|
||||
await switchClient.stop()
|
||||
await switchRelay.stop()
|
||||
let addresses = autorelay.getAddresses()
|
||||
check:
|
||||
addresses[0] == buildRelayMA(switchRelay, switchClient)
|
||||
addresses.len() == 1
|
||||
await allFutures(switchClient.stop(), switchRelay.stop())
|
||||
|
||||
asyncTest "Three relays connections":
|
||||
var state = 0
|
||||
let
|
||||
rel1 = createSwitch(Relay.new())
|
||||
rel2 = createSwitch(Relay.new())
|
||||
rel3 = createSwitch(Relay.new())
|
||||
fut = newFuture[void]()
|
||||
relayClient = RelayClient.new()
|
||||
proc checkMA(addresses: seq[MultiAddress]) =
|
||||
if state == 0 or state == 2:
|
||||
check:
|
||||
buildRelayMA(rel1, switchClient) in addresses
|
||||
addresses.len() == 1
|
||||
state += 1
|
||||
elif state == 1:
|
||||
check:
|
||||
buildRelayMA(rel1, switchClient) in addresses
|
||||
buildRelayMA(rel2, switchClient) in addresses
|
||||
addresses.len() == 2
|
||||
state += 1
|
||||
elif state == 3:
|
||||
check:
|
||||
buildRelayMA(rel1, switchClient) in addresses
|
||||
buildRelayMA(rel3, switchClient) in addresses
|
||||
addresses.len() == 2
|
||||
state += 1
|
||||
fut.complete()
|
||||
let autorelay = AutoRelayService.new(2, relayClient, checkMA, newRng())
|
||||
switchClient = createSwitch(relayClient, autorelay)
|
||||
await allFutures(switchClient.start(), rel1.start(), rel2.start(), rel3.start())
|
||||
await switchClient.connect(rel1.peerInfo.peerId, rel1.peerInfo.addrs)
|
||||
discard autorelay.run(switchClient)
|
||||
await sleepAsync(500.millis)
|
||||
await switchClient.connect(rel2.peerInfo.peerId, rel2.peerInfo.addrs)
|
||||
await switchClient.connect(rel3.peerInfo.peerId, rel3.peerInfo.addrs)
|
||||
await sleepAsync(500.millis)
|
||||
await rel2.stop()
|
||||
await fut.wait(1.seconds)
|
||||
let addresses = autorelay.getAddresses()
|
||||
check:
|
||||
buildRelayMA(rel1, switchClient) in addresses
|
||||
buildRelayMA(rel3, switchClient) in addresses
|
||||
addresses.len() == 2
|
||||
await allFutures(switchClient.stop(), rel1.stop(), rel3.stop())
|
||||
|
Loading…
x
Reference in New Issue
Block a user