From df40f4c6e3806977b4e09388e7041a1f21d25cf7 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 15 Jun 2026 22:26:36 +0400 Subject: [PATCH] Refactoring --- .../not-downloadable/testnotdownloadable.nim | 34 +++---------------- .../nat/not-reachable/testnotreachable.nim | 18 +--------- tests/integration/nat/pcp/testpcp.nim | 18 +--------- .../nat/reachable/testreachable.nim | 18 +--------- tests/integration/nat/upnp/testupnp.nim | 18 +--------- 5 files changed, 8 insertions(+), 98 deletions(-) diff --git a/tests/integration/nat/not-downloadable/testnotdownloadable.nim b/tests/integration/nat/not-downloadable/testnotdownloadable.nim index 393ddabb..d6a4fb30 100644 --- a/tests/integration/nat/not-downloadable/testnotdownloadable.nim +++ b/tests/integration/nat/not-downloadable/testnotdownloadable.nim @@ -19,10 +19,6 @@ import ../../../checktest import ../../storageclient import ../composehelper -const - detectTimeout = 300_000 # ms - pollInterval = 5_000 # ms - proc announcesNothing(info: JsonNode): bool = ## An unreachable node with no relay has no dialable address to announce. info{"announceAddresses"}.getElems.len == 0 @@ -53,19 +49,9 @@ asyncchecksuite "NAT not downloadable": test testName: # Make sure nodeClient is not reachable - check eventuallySafe( - block: - var settled = false - try: - let info = await nodeClient.info() - settled = - info.isOk and info.get{"nat"}{"reachability"}.getStr == "NotReachable" and - info.get.announcesNothing() - except HttpError: - discard - settled, - timeout = detectTimeout, - pollInterval = pollInterval, + check eventuallyInfo( + nodeClient, + info{"nat"}{"reachability"}.getStr == "NotReachable" and info.announcesNothing(), ) let info = (await nodeClient.info()).get @@ -74,19 +60,7 @@ asyncchecksuite "NAT not downloadable": check info.announcesNothing() # C is reachable - check eventuallySafe( - block: - var reachable = false - try: - let cInfo = await clientC.info() - reachable = - cInfo.isOk and cInfo.get{"nat"}{"reachability"}.getStr == "Reachable" - except HttpError: - discard - reachable, - timeout = detectTimeout, - pollInterval = pollInterval, - ) + check eventuallyInfo(clientC, info{"nat"}{"reachability"}.getStr == "Reachable") # B uploads a file let cid = (await nodeClient.upload("hello from behind the NAT")).get diff --git a/tests/integration/nat/not-reachable/testnotreachable.nim b/tests/integration/nat/not-reachable/testnotreachable.nim index eefd47ab..33f4b510 100644 --- a/tests/integration/nat/not-reachable/testnotreachable.nim +++ b/tests/integration/nat/not-reachable/testnotreachable.nim @@ -13,10 +13,6 @@ import ../../../checktest import ../../storageclient import ../composehelper -const - detectTimeout = 300_000 # ms - pollInterval = 5_000 # ms - proc announcesCircuitAddr(info: JsonNode): bool = info{"announceAddresses"}.getElems.anyIt("p2p-circuit" in it.getStr) @@ -41,19 +37,7 @@ asyncchecksuite "NAT not reachable": test testName: # Wait for the announcements, after the relay reservation is created. - check eventuallySafe( - block: - var settled = false - try: - let info = await client.info() - settled = info.isOk and info.get.announcesCircuitAddr() - except HttpError: - # B's API is not up yet, keep polling - discard - settled, - timeout = detectTimeout, - pollInterval = pollInterval, - ) + check eventuallyInfo(client, info.announcesCircuitAddr()) let info = (await client.info()).get let nat = info{"nat"} diff --git a/tests/integration/nat/pcp/testpcp.nim b/tests/integration/nat/pcp/testpcp.nim index 2785f6d6..6300bc3e 100644 --- a/tests/integration/nat/pcp/testpcp.nim +++ b/tests/integration/nat/pcp/testpcp.nim @@ -18,10 +18,6 @@ import ../../../checktest import ../../storageclient import ../composehelper -const - detectTimeout = 300_000 # ms - pollInterval = 5_000 # ms - proc announcesDirectAddr(info: JsonNode): bool = ## A reachable node announces at least one direct (non-circuit) address. info{"announceAddresses"}.getElems.anyIt("p2p-circuit" notin it.getStr) @@ -48,19 +44,7 @@ asyncchecksuite "NAT pcp": test testName: # Reachable is the settling signal: wait for it, then assert each expected # property separately so a failure points at the exact condition. - check eventuallySafe( - block: - var reachable = false - try: - let info = await client.info() - reachable = - info.isOk and info.get{"nat"}{"reachability"}.getStr == "Reachable" - except HttpError: - discard # B's API is not up yet, keep polling - reachable, - timeout = detectTimeout, - pollInterval = pollInterval, - ) + check eventuallyInfo(client, info{"nat"}{"reachability"}.getStr == "Reachable") let info = (await client.info()).get let nat = info{"nat"} diff --git a/tests/integration/nat/reachable/testreachable.nim b/tests/integration/nat/reachable/testreachable.nim index adefe598..7d5b1110 100644 --- a/tests/integration/nat/reachable/testreachable.nim +++ b/tests/integration/nat/reachable/testreachable.nim @@ -19,10 +19,6 @@ import ../../../checktest import ../../storageclient import ../composehelper -const - detectTimeout = 120_000 # ms - pollInterval = 5_000 # ms - proc announcesDirectAddr(info: JsonNode): bool = ## A reachable node announces at least one direct (non-circuit) address. info{"announceAddresses"}.getElems.anyIt("p2p-circuit" notin it.getStr) @@ -49,19 +45,7 @@ asyncchecksuite "NAT reachable": test testName: # Reachable is the settling signal: wait for it, then assert each expected # property separately so a failure points at the exact condition. - check eventuallySafe( - block: - var reachable = false - try: - let info = await client.info() - reachable = - info.isOk and info.get{"nat"}{"reachability"}.getStr == "Reachable" - except HttpError: - discard # B's API is not up yet, keep polling - reachable, - timeout = detectTimeout, - pollInterval = pollInterval, - ) + check eventuallyInfo(client, info{"nat"}{"reachability"}.getStr == "Reachable") let info = (await client.info()).get let nat = info{"nat"} diff --git a/tests/integration/nat/upnp/testupnp.nim b/tests/integration/nat/upnp/testupnp.nim index e22e812d..7f69facc 100644 --- a/tests/integration/nat/upnp/testupnp.nim +++ b/tests/integration/nat/upnp/testupnp.nim @@ -18,10 +18,6 @@ import ../../../checktest import ../../storageclient import ../composehelper -const - detectTimeout = 300_000 # ms - pollInterval = 5_000 # ms - proc announcesDirectAddr(info: JsonNode): bool = ## A reachable node announces at least one direct (non-circuit) address. info{"announceAddresses"}.getElems.anyIt("p2p-circuit" notin it.getStr) @@ -48,19 +44,7 @@ asyncchecksuite "NAT upnp": test testName: # Reachable is the settling signal: wait for it, then assert each expected # property separately so a failure points at the exact condition. - check eventuallySafe( - block: - var reachable = false - try: - let info = await client.info() - reachable = - info.isOk and info.get{"nat"}{"reachability"}.getStr == "Reachable" - except HttpError: - discard # B's API is not up yet, keep polling - reachable, - timeout = detectTimeout, - pollInterval = pollInterval, - ) + check eventuallyInfo(client, info{"nat"}{"reachability"}.getStr == "Reachable") let info = (await client.info()).get let nat = info{"nat"}