Skip to content

Commit 7bf1162

Browse files
committed
test quic
1 parent bf2f3e6 commit 7bf1162

6 files changed

Lines changed: 35 additions & 36 deletions

File tree

.pinned

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ json_serialization;https://github.com/status-im/nim-json-serialization@#2b1c5eb1
88
metrics;https://github.com/status-im/nim-metrics@#6142e433fc8ea9b73379770a788017ac528d46ff
99
ngtcp2;https://github.com/status-im/nim-ngtcp2@#791eb859145f9f268eb23eb9cbe777bdd7699c4d
1010
nimcrypto;https://github.com/cheatfate/nimcrypto@#19c41d6be4c00b4a2c8000583bd30cf8ceb5f4b1
11-
quic;https://github.com/vacp2p/nim-quic@#525842aeca6111fd5035568d0f59aa2b338cc29d
11+
quic;https://github.com/vacp2p/nim-quic@#865e27d550b32b24d708c15f0e3b7591f94a093c
1212
results;https://github.com/arnetheduck/nim-results@#df8113dda4c2d74d460a8fa98252b0b771bf1f27
1313
secp256k1;https://github.com/status-im/nim-secp256k1@#f808ed5e7a7bfc42204ec7830f14b7a42b63c284
1414
serialization;https://github.com/status-im/nim-serialization@#548d0adc9797a10b2db7f788b804330306293088

tests/helpers.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ macro checkUntilTimeoutCustom*(
154154
await checkExpiringInternal()
155155

156156
macro checkUntilTimeout*(code: untyped): untyped =
157-
## Same as `checkUntilTimeoutCustom` but with a default timeout of 2s with 50ms interval.
157+
## Same as `checkUntilTimeoutCustom` but with a default timeout of 30s with 50ms interval.
158158
##
159159
## Examples:
160160
## ```nim
@@ -175,7 +175,7 @@ macro checkUntilTimeout*(code: untyped): untyped =
175175
## b == 1
176176
## ```
177177
result = quote:
178-
checkUntilTimeoutCustom(2.seconds, 50.milliseconds, `code`)
178+
checkUntilTimeoutCustom(30.seconds, 50.milliseconds, `code`)
179179

180180
proc unorderedCompare*[T](a, b: seq[T]): bool =
181181
if a == b:

tests/pubsub/integration/testfloodsub.nim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,12 @@ suite "FloodSub Integration":
247247
# test calling unsubscribeAll for coverage
248248
for node in nodes:
249249
node.unsubscribeAll("foobar")
250-
check:
250+
let n = node
251+
checkUntilTimeout:
251252
# we keep the peers in table
252-
FloodSub(node).floodsub["foobar"].len == 9
253+
FloodSub(n).floodsub["foobar"].len == 9
253254
# remove the topic tho
254-
node.topics.len == 0
255+
n.topics.len == 0
255256

256257
asyncTest "FloodSub message size validation":
257258
var messageReceived = 0

tests/pubsub/integration/testgossipsubmeshmanagement.nim

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ suite "GossipSub Integration - Mesh Management":
4040

4141
asyncTest "Nodes graft peers according to DValues - numberOfNodes > dHigh":
4242
let
43-
numberOfNodes = 15
43+
numberOfNodes = 8
4444
topic = "foobar"
4545
nodes = generateNodes(numberOfNodes, gossip = true).toGossipSub()
4646

@@ -50,17 +50,19 @@ suite "GossipSub Integration - Mesh Management":
5050

5151
let
5252
expectedNumberOfPeers = numberOfNodes - 1
53-
dHigh = 12
53+
dHigh = 7
5454
d = 6
5555
dLow = 4
5656

5757
for i in 0 ..< numberOfNodes:
5858
let node = nodes[i]
5959
checkUntilTimeout:
60+
node.fanout.len == 0
6061
node.gossipsub.getOrDefault(topic).len == expectedNumberOfPeers
61-
node.mesh.getOrDefault(topic).len >= dLow and
62+
(
63+
node.mesh.getOrDefault(topic).len >= dLow and
6264
node.mesh.getOrDefault(topic).len <= dHigh
63-
node.fanout.len == 0
65+
)
6466

6567
asyncTest "GossipSub should add remote peer topic subscriptions":
6668
proc handler(topic: string, data: seq[byte]) {.async.} =
@@ -338,25 +340,21 @@ suite "GossipSub Integration - Mesh Management":
338340
checkUntilTimeout:
339341
node0.mesh.getOrDefault(topic).len == dValues.get.d.get
340342

341-
# TODO: Remove loop when GossipSub tests fully switched to QUIC
342-
const transports = @[TransportType.TCP, TransportType.QUIC]
343-
for transport in transports:
344-
asyncTest "Outbound peers are marked correctly " & $transport:
345-
let
346-
numberOfNodes = 4
347-
topic = "foobar"
348-
nodes = generateNodes(numberOfNodes, gossip = true, transport = transport)
349-
.toGossipSub()
350-
351-
startNodesAndDeferStop(nodes)
352-
353-
await connectNodes(nodes[0], nodes[1]) # Out
354-
await connectNodes(nodes[0], nodes[2]) # Out
355-
await connectNodes(nodes[3], nodes[0]) # In
356-
subscribeAllNodes(nodes, topic, voidTopicHandler)
343+
asyncTest "Outbound peers are marked correctly ":
344+
let
345+
numberOfNodes = 4
346+
topic = "foobar"
347+
nodes = generateNodes(numberOfNodes, gossip = true).toGossipSub()
357348

358-
checkUntilTimeout:
359-
nodes[0].mesh.outboundPeers(topic) == 2
360-
nodes[0].getPeerByPeerId(topic, nodes[1].peerInfo.peerId).outbound == true
361-
nodes[0].getPeerByPeerId(topic, nodes[2].peerInfo.peerId).outbound == true
362-
nodes[0].getPeerByPeerId(topic, nodes[3].peerInfo.peerId).outbound == false
349+
startNodesAndDeferStop(nodes)
350+
351+
await connectNodes(nodes[0], nodes[1]) # Out
352+
await connectNodes(nodes[0], nodes[2]) # Out
353+
await connectNodes(nodes[3], nodes[0]) # In
354+
subscribeAllNodes(nodes, topic, voidTopicHandler)
355+
356+
checkUntilTimeout:
357+
nodes[0].mesh.outboundPeers(topic) == 2
358+
nodes[0].getPeerByPeerId(topic, nodes[1].peerInfo.peerId).outbound == true
359+
nodes[0].getPeerByPeerId(topic, nodes[2].peerInfo.peerId).outbound == true
360+
nodes[0].getPeerByPeerId(topic, nodes[3].peerInfo.peerId).outbound == false

tests/pubsub/integration/testgossipsubscoring.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ suite "GossipSub Integration - Scoring":
8383
)
8484
await waitForHeartbeat()
8585

86-
check:
86+
checkUntilTimeout:
8787
currentRateLimitHits() == rateLimitHits
8888
nodes[1].switch.isConnected(nodes[0].switch.peerInfo.peerId) == true
8989

@@ -96,7 +96,7 @@ suite "GossipSub Integration - Scoring":
9696
)
9797
await waitForHeartbeat()
9898

99-
check:
99+
checkUntilTimeout:
100100
nodes[1].switch.isConnected(nodes[0].switch.peerInfo.peerId) == true
101101
currentRateLimitHits() == rateLimitHits
102102

tests/pubsub/utils.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ proc generateNodes*(
192192
publishThreshold = -1000.0,
193193
graylistThreshold = -10000.0,
194194
disconnectBadPeers: bool = false,
195-
transport: TransportType = TransportType.TCP,
195+
transport: TransportType = TransportType.QUIC,
196196
): seq[PubSub] =
197197
for i in 0 ..< num:
198198
let switch = newStandardSwitch(
@@ -537,9 +537,9 @@ proc baseTestProcedure*(
537537

538538
block setup:
539539
for i in 0 ..< 50:
540-
if (await nodes[0].publish("foobar", ("Hello!" & $i).toBytes())) == 19:
540+
if (await nodes[0].publish("foobar", ("Hello!" & $i).toBytes())) == nodes.len - 1:
541541
break setup
542-
await sleepAsync(10.milliseconds)
542+
await sleepAsync(1.seconds)
543543
check false
544544

545545
check (await nodes[0].publish("foobar", newSeq[byte](2_500_000))) == numPeersFirstMsg

0 commit comments

Comments
 (0)