From 7ec78ee4a2836c6c7d07e5a2726220a29c6c05f0 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Sat, 3 Oct 2026 07:24:24 +0800 Subject: [PATCH] [nexus] increase advance time in border agent wrong key test (#13662) This commit fixes a test flakiness issue in `nexus_border_agent` where `TestBorderAgentEphemeralKey` and `TestHistoryTrackerBorderAgentEpskcEvent` attempted consecutive DTLS connections with the wrong key in a loop. When a secure session disconnects, `SecureSession::Disconnect` starts a 2-second guard timer (`kGuardTimeNewConnectionMilli`) before transitioning the session to `kStateDisconnected`. If the DTLS handshake took longer than expected (e.g. due to simulated MAC backoff or packet retransmission), advancing a fixed 3 seconds left the session in `kStateDisconnecting`, causing the subsequent `Connect()` call on the same `SecureAgent` to fail with `kErrorInvalidState`. This change increases the advance time from 3 to 6 seconds (well within the 120-second default ephemeral key lifetime) and adds checks to verify that the session is no longer active before initiating the next connection attempt, avoiding unbounded loops while preventing flakiness. --- tests/nexus/test_border_agent.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/nexus/test_border_agent.cpp b/tests/nexus/test_border_agent.cpp index 3d70d2032..58c5deebd 100644 --- a/tests/nexus/test_border_agent.cpp +++ b/tests/nexus/test_border_agent.cpp @@ -584,9 +584,10 @@ void TestBorderAgentEphemeralKey(void) SuccessOrQuit(node1.Get().Connect(sockAddr)); - nexus.AdvanceTime(3 * Time::kOneSecondInMsec); + nexus.AdvanceTime(6 * Time::kOneSecondInMsec); VerifyOrQuit(!node1.Get().IsConnected()); + VerifyOrQuit(!node1.Get().IsConnectionActive()); VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStarted); } @@ -594,7 +595,7 @@ void TestBorderAgentEphemeralKey(void) sEphemeralKeyCallbackCalled = false; SuccessOrQuit(node1.Get().Connect(sockAddr)); - nexus.AdvanceTime(3 * Time::kOneSecondInMsec); + nexus.AdvanceTime(6 * Time::kOneSecondInMsec); VerifyOrQuit(!node1.Get().IsConnected()); VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStopped); @@ -912,16 +913,17 @@ void TestHistoryTrackerBorderAgentEpskcEvent(void) SuccessOrQuit(node1.Get().Connect(sockAddr)); - nexus.AdvanceTime(3 * Time::kOneSecondInMsec); + nexus.AdvanceTime(6 * Time::kOneSecondInMsec); VerifyOrQuit(!node1.Get().IsConnected()); + VerifyOrQuit(!node1.Get().IsConnectionActive()); VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStarted); } Log(" Attempt 10 (final attempt) to connect with the wrong key, check that ephemeral key use is stopped"); SuccessOrQuit(node1.Get().Connect(sockAddr)); - nexus.AdvanceTime(3 * Time::kOneSecondInMsec); + nexus.AdvanceTime(6 * Time::kOneSecondInMsec); VerifyOrQuit(!node1.Get().IsConnected()); VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStopped);