From d5715a1f4f57a73649641a448be2635f08fb0f21 Mon Sep 17 00:00:00 2001 From: evgeny Date: Sat, 17 Oct 2026 16:26:35 +0200 Subject: [PATCH] tests: wait for the requested NAT round instead of an earlier automatic result --- tests/stream_netns/README.md | 2 +- tests/test_nat_detection_faults.c | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/stream_netns/README.md b/tests/stream_netns/README.md index 87b7b0d8..b1244e24 100644 --- a/tests/stream_netns/README.md +++ b/tests/stream_netns/README.md @@ -22,7 +22,7 @@ python3 tests/stream_netns/run.py python3 tests/stream_netns/run.py --nat-only --tcp ``` -Резервное определение типа STUN на отдельных портах и переход к измерению ETCP: +Независимая STUN-диагностика отдельных портов и измерение рабочего endpoint через ETCP: ```sh python3 tests/stream_netns/run.py --stun-only --output /tmp/stun-interface-netns diff --git a/tests/test_nat_detection_faults.c b/tests/test_nat_detection_faults.c index 49145dca..8bbae4a9 100644 --- a/tests/test_nat_detection_faults.c +++ b/tests/test_nat_detection_faults.c @@ -127,11 +127,12 @@ static void run_case(enum fault_mode mode, uint8_t mapping, uint8_t inbound) { nat_detection_set_automatic(owner->nat_det, 0); memset(&fault, 0, sizeof(fault)); fault.fixture = &fixture; fault.owner = owner; fault.observer = observer; fault.helper = helper; fault.socket = test_etcp_bound_socket(owner, "udp"); fault.mode = mode; - assert(!nat_detection_request_check_socket(owner->nat_det, fault.socket, observer->node_id)); struct nat_check_status status = {0}; + nat_detection_get_status(owner->nat_det, fault.socket, &status); uint32_t rounds = status.rounds; + assert(!nat_detection_request_check_socket(owner->nat_det, fault.socket, observer->node_id)); uint64_t end = get_time_tb() + 400000; do { test_clock_poll(fixture.ua, 1000); assert(!nat_detection_get_status(owner->nat_det, fault.socket, &status)); } - while (get_time_tb() < end && (!status.rounds || status.phase || status.cycling)); + while (get_time_tb() < end && (status.rounds == rounds || status.phase || status.cycling)); DEBUG_INFO(DEBUG_CATEGORY_NAT, "fault fixture result mode=%d mapping=%s inbound=%s phase=%u cycling=%u reason=%s dropped=%u observations=%u", mode, address_mapping_name(fault.socket->address_profile.mapping), address_inbound_name(fault.socket->address_profile.inbound), status.phase, status.cycling, nat_check_reason_name(status.reason), fault.dropped, fault.observations); @@ -163,10 +164,11 @@ static void run_alias(const char *alias_ip) { struct ETCP_SOCKET *socket = test_etcp_bound_socket(owner, "udp"); memset(&fault, 0, sizeof(fault)); fault.fixture = &fixture; fault.owner = owner; fault.socket = socket; fault.observer = observer; fault.helper = helper; fault.alias = alias; fault.alias_source = test_etcp_bound_socket(alias, "alias"); - assert(!nat_detection_request_check_socket(owner->nat_det, socket, observer->node_id)); struct nat_check_status status = {0}; uint64_t end = get_time_tb() + 400000; + nat_detection_get_status(owner->nat_det, socket, &status); uint32_t rounds = status.rounds; + assert(!nat_detection_request_check_socket(owner->nat_det, socket, observer->node_id)); do { test_clock_poll(fixture.ua, 1000); assert(!nat_detection_get_status(owner->nat_det, socket, &status)); } - while (get_time_tb() < end && (!status.rounds || status.phase || status.cycling)); + while (get_time_tb() < end && (status.rounds == rounds || status.phase || status.cycling)); assert(socket->address_profile.mapping == ADDRESS_MAP_UNCHANGED && socket->address_profile.inbound == ADDRESS_IN_OPEN); DEBUG_INFO(DEBUG_CATEGORY_NAT, "alias fixture result source=%s helper=%016llx expected=%016llx reselections=%u remapped=%u", alias_ip, (unsigned long long)status.helper, (unsigned long long)helper->node_id, @@ -191,10 +193,14 @@ static void run_endpoint_retry(void) { nat_fixture_connect(&fixture, observer, "tcp", helper); nat_fixture_connect(&fixture, owner, "tcp", observer); nat_detection_set_automatic(owner->nat_det, 0); struct ETCP_SOCKET *socket = test_etcp_bound_socket(owner, "udp"); - assert(!nat_detection_request_check_socket(owner->nat_det, socket, observer->node_id)); struct nat_check_status status = {0}; uint64_t end = get_time_tb() + 400000; + nat_detection_get_status(owner->nat_det, socket, &status); uint32_t rounds = status.rounds; + assert(!nat_detection_request_check_socket(owner->nat_det, socket, observer->node_id)); do { test_clock_poll(fixture.ua, 1000); assert(!nat_detection_get_status(owner->nat_det, socket, &status)); } - while (get_time_tb() < end && (!status.rounds || status.phase || status.cycling)); + while (get_time_tb() < end && (status.rounds == rounds || status.phase || status.cycling)); + DEBUG_INFO(DEBUG_CATEGORY_NAT, "endpoint fixture result mapping=%s inbound=%s rounds=%u previous=%u reason=%s", + address_mapping_name(socket->address_profile.mapping), address_inbound_name(socket->address_profile.inbound), + status.rounds, rounds, nat_check_reason_name(status.reason)); assert(socket->address_profile.mapping == ADDRESS_MAP_UNCHANGED && socket->address_profile.inbound == ADDRESS_IN_OPEN); assert(status.helper_reselections && status.observer == observer->node_id); nat_fixture_cleanup(&fixture);