-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathtestdialer.nim
59 lines (46 loc) · 1.64 KB
/
testdialer.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Nim-LibP2P
# Copyright (c) 2023 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
# at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
import std/options
import chronos
import sequtils
import unittest2
import ../libp2p/[builders, switch]
import ./helpers
suite "Dialer":
teardown:
checkTrackers()
asyncTest "Connect forces a new connection":
let
src = newStandardSwitch()
dst = newStandardSwitch()
await dst.start()
await src.connect(dst.peerInfo.peerId, dst.peerInfo.addrs)
check src.connManager.connCount(dst.peerInfo.peerId) == 1
await src.connect(dst.peerInfo.peerId, dst.peerInfo.addrs)
check src.connManager.connCount(dst.peerInfo.peerId) == 1
await src.connect(dst.peerInfo.peerId, dst.peerInfo.addrs, true, false)
check src.connManager.connCount(dst.peerInfo.peerId) == 2
await allFutures(src.stop(), dst.stop())
asyncTest "Max connections reached":
var switches: seq[Switch]
let dst = newStandardSwitch(maxConnections = 2)
await dst.start()
switches.add(dst)
for i in 1 ..< 3:
let src = newStandardSwitch()
switches.add(src)
await src.start()
await src.connect(dst.peerInfo.peerId, dst.peerInfo.addrs, true, false)
let src = newStandardSwitch()
switches.add(src)
await src.start()
check not await src.connect(dst.peerInfo.peerId, dst.peerInfo.addrs).withTimeout(
1000.millis
)
await allFuturesThrowing(allFutures(switches.mapIt(it.stop())))