Improve tests checking

This commit is contained in:
Arnaud 2026-05-13 10:04:50 +04:00
parent 3e982b4af3
commit 294899a391
No known key found for this signature in database
GPG Key ID: A6C7C781817146FA
2 changed files with 41 additions and 140 deletions

View File

@ -13,6 +13,28 @@ const
RelayTimeout = 30_000
PollInterval = 1_000
proc checkNatReachability*(client: StorageClient, reachability: string) {.async.} =
check eventuallySafe(
(await client.natReachability()).get() == reachability,
timeout = RelayTimeout,
pollInterval = PollInterval,
)
proc checkRelayIsRunning*(client: StorageClient, isRunning: bool) {.async.} =
check eventuallySafe(
(await client.natRelayRunning()).get() == isRunning,
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
block:
let addrs = (await client.info()).get["addrs"].getElems.mapIt(it.getStr)
addrs.anyIt("p2p-circuit" in it) == isRunning,
timeout = RelayTimeout,
pollInterval = PollInterval,
)
# Reminder: multinodesuite setup the first node as bootstrap node
multinodesuite "AutoNAT detection":
let natConfig = NodeConfigs(
@ -26,18 +48,8 @@ multinodesuite "AutoNAT detection":
)
test "node is reachable when using bootstrap node on same network", natConfig:
let node2 = clients()[1]
check eventuallySafe(
(await node2.client.natReachability()).get() == "Reachable",
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
not (await node2.client.natRelayRunning()).get(),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
await node2.client.checkNatReachability("Reachable")
await node2.client.checkRelayIsRunning(false)
let endpointIndependentConfig = NodeConfigs(
clients: StorageConfigs
@ -52,18 +64,8 @@ multinodesuite "AutoNAT detection":
# EIF = Endpoint Independent Filtering
test "node with simulated EIF nat is detected as reachable", endpointIndependentConfig:
let node2 = clients()[1]
check eventuallySafe(
(await node2.client.natReachability()).get() == "Reachable",
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
not (await node2.client.natRelayRunning()).get(),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
await node2.client.checkNatReachability("Reachable")
await node2.client.checkRelayIsRunning(false)
let autonatConfig = NodeConfigs(
clients: StorageConfigs
@ -79,26 +81,8 @@ multinodesuite "AutoNAT detection":
test "node with simulated APDF nat is detected as not reachable and starts relay",
autonatConfig:
let node2 = clients()[1]
check eventuallySafe(
(await node2.client.natReachability()).get() == "NotReachable",
timeout = DetectionTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
(await node2.client.natRelayRunning()).get(),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
block:
let addrs = (await node2.client.info()).get["addrs"].getElems.mapIt(it.getStr)
addrs.anyIt("p2p-circuit" in it),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
await node2.client.checkNatReachability("NotReachable")
await node2.client.checkRelayIsRunning(true)
let transitionConfig = NodeConfigs(
clients: StorageConfigs
@ -116,39 +100,13 @@ multinodesuite "AutoNAT detection":
transitionConfig:
let node2 = clients()[1]
check eventuallySafe(
(await node2.client.natReachability()).get() == "NotReachable",
timeout = DetectionTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
(await node2.client.natRelayRunning()).get(),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
block:
let addrs = (await node2.client.info()).get["addrs"].getElems.mapIt(it.getStr)
addrs.anyIt("p2p-circuit" in it),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
await node2.client.checkNatReachability("NotReachable")
await node2.client.checkRelayIsRunning(true)
check (await node2.client.setNatFiltering("endpoint-independent")).isOk
check eventuallySafe(
(await node2.client.natReachability()).get() == "Reachable",
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
not (await node2.client.natRelayRunning()).get(),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
await node2.client.checkNatReachability("Reachable")
await node2.client.checkRelayIsRunning(false)
let natToSimConfig = NodeConfigs(
clients: StorageConfigs
@ -160,37 +118,18 @@ multinodesuite "AutoNAT detection":
.withNatScheduleInterval(5.seconds)
.withNatMaxQueueSize(1).some
)
# APDF = Address and Port-Dependent Filtering
test "reachable node becomes not reachable and starts relay when nat switches to APDF nat",
natToSimConfig:
let node2 = clients()[1]
check eventuallySafe(
(await node2.client.natReachability()).get() == "Reachable",
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
not (await node2.client.natRelayRunning()).get(),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
await node2.client.checkNatReachability("Reachable")
await node2.client.checkRelayIsRunning(false)
check (await node2.client.setNatFiltering("address-and-port-dependent")).isOk
check eventuallySafe(
(await node2.client.natReachability()).get() == "NotReachable",
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
(await node2.client.natRelayRunning()).get(),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
await node2.client.checkNatReachability("NotReachable")
await node2.client.checkRelayIsRunning(true)
let multiNatConfig = NodeConfigs(
clients: StorageConfigs
@ -203,49 +142,13 @@ multinodesuite "AutoNAT detection":
.withNatScheduleInterval(5.seconds)
.withNatMaxQueueSize(1).some
)
# APDF = Address and Port-Dependent Filtering
test "two nodes with simulated APDF nat starts relay through the same relay node",
multiNatConfig:
let node2 = clients()[1]
let node3 = clients()[2]
check eventuallySafe(
(await node2.client.natReachability()).get() == "NotReachable",
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
(await node3.client.natReachability()).get() == "NotReachable",
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
(await node2.client.natRelayRunning()).get(),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
(await node3.client.natRelayRunning()).get(),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
block:
let addrs = (await node2.client.info()).get["addrs"].getElems.mapIt(it.getStr)
addrs.anyIt("p2p-circuit" in it),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
check eventuallySafe(
block:
let addrs = (await node3.client.info()).get["addrs"].getElems.mapIt(it.getStr)
addrs.anyIt("p2p-circuit" in it),
timeout = RelayTimeout,
pollInterval = PollInterval,
)
await node2.client.checkNatReachability("NotReachable")
await node3.client.checkNatReachability("NotReachable")
await node2.client.checkRelayIsRunning(true)
await node3.client.checkRelayIsRunning(true)

View File

@ -46,9 +46,7 @@ multinodesuite "NAT download":
let natNode = clients()[2]
check eventuallySafe(
block:
let addrs = (await natNode.client.info()).get["addrs"].getElems.mapIt(it.getStr)
addrs.anyIt("p2p-circuit" in it),
(await natNode.client.natRelayRunning()).get(),
timeout = RelayTimeout,
pollInterval = PollInterval,
)