Skip to content

Commit ee14e03

Browse files
sanityclaude
andcommitted
test: force connection teardown to catch NAT routing bugs deterministically
Add connection teardown step in test_put_contract_three_hop_returns_response after PUT completes but before verifying responses. This ensures the test validates address-based routing rather than relying on existing connections. Previously the test was flaky because: - If bidirectional UDP connections remained active, responses could arrive via existing connections even with incorrect address routing - Whether the test passed depended on timing/NAT state expiration Now the test deterministically catches NAT routing bugs like the one fixed in PR #2243 where responses were routed to internal addresses instead of external addresses. Addresses review feedback from @iduartgomez. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9e3722a commit ee14e03

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

crates/core/tests/operations.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,28 @@ async fn test_put_contract_three_hop_returns_response(ctx: &mut TestContext) ->
20472047
)
20482048
.await?;
20492049

2050+
// CRITICAL: Force connection teardown to ensure response routing uses addresses,
2051+
// not existing connections. This makes the test deterministically catch NAT routing
2052+
// bugs where responses would be routed to wrong (internal) addresses.
2053+
//
2054+
// Without this, the test was flaky because:
2055+
// - If the bidirectional UDP connection was still active, responses might arrive
2056+
// via the existing connection even with wrong address routing
2057+
// - If NAT state expired or connection was torn down, routing would fail
2058+
//
2059+
// By forcing disconnection and reconnection, we ensure the test validates
2060+
// address-based routing, catching bugs like the one fixed in PR #2243.
2061+
tracing::info!("Forcing connection teardown to validate address-based routing");
2062+
client_api_a
2063+
.send(ClientRequest::Disconnect { cause: None })
2064+
.await?;
2065+
tokio::time::sleep(Duration::from_secs(2)).await;
2066+
2067+
// Reconnect to peer A - if there were any pending responses that relied on
2068+
// wrong address routing, they will now fail to arrive
2069+
let (stream_a, _) = connect_async(&uri_a).await?;
2070+
let mut client_api_a = WebApi::start(stream_a);
2071+
20502072
// Verify contract can be retrieved from peer C
20512073
let uri_c = format!(
20522074
"ws://127.0.0.1:{}/v1/contract/command?encodingProtocol=native",

0 commit comments

Comments
 (0)