Refactoring

This commit is contained in:
Arnaud 2026-06-15 22:26:36 +04:00
parent bdbd9ed543
commit df40f4c6e3
No known key found for this signature in database
GPG Key ID: A6C7C781817146FA
5 changed files with 8 additions and 98 deletions

View File

@ -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

View File

@ -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"}

View File

@ -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"}

View File

@ -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"}

View File

@ -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"}