From 294899a391a9c1e58f506b626b51ca4f35d8ebba Mon Sep 17 00:00:00 2001 From: Arnaud Date: Wed, 13 May 2026 10:04:50 +0400 Subject: [PATCH] Improve tests checking --- tests/integration/1_minute/testnat.nim | 177 ++++-------------- .../integration/5_minutes/testnatdownload.nim | 4 +- 2 files changed, 41 insertions(+), 140 deletions(-) diff --git a/tests/integration/1_minute/testnat.nim b/tests/integration/1_minute/testnat.nim index 0edfeedd..7402eb74 100644 --- a/tests/integration/1_minute/testnat.nim +++ b/tests/integration/1_minute/testnat.nim @@ -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) diff --git a/tests/integration/5_minutes/testnatdownload.nim b/tests/integration/5_minutes/testnatdownload.nim index 365217d2..8407ebb5 100644 --- a/tests/integration/5_minutes/testnatdownload.nim +++ b/tests/integration/5_minutes/testnatdownload.nim @@ -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, )