Skip to content

Commit 706e93f

Browse files
authored
[nexus] fix flaky nexus test router_downgrade_on_sec_policy_change (openthread#12959)
The test was failing occasionally due to the unpredictable timing of tick-aligned timers and dataset propagation in simulations. Specifically: 1) The router's jittered timeout (minimum 1 second) could expire in as little as 1ms if an MLE TimeTick occurred immediately after the security policy update. 2) Dataset propagation via MLE Advertisements could take up to 32 seconds, making immediate checks on the router's role unreliable. This commit fixes the flakiness by: - Replacing flaky router role checks with `IsRouterRoleAllowed()` assertions. This verifies that the security policy has been successfully propagated and applied, regardless of whether the actual role transition has completed. - Increasing the propagation wait time to 5 seconds. This provides a safe margin for simulated radio propagation while remaining well within the leader's 10-second downgrade delay. - Ensuring both the leader and router are verified for policy application in both phases of the test. - Maintaining the final checks to ensure both nodes eventually become detached after the full downgrade delay (150 seconds). The fix was verified with 1000 consecutive successful iterations.
1 parent 0a97d56 commit 706e93f

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

tests/nexus/test_router_downgrade_on_sec_policy_change.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,20 @@ void TestRouterDowngradeOnSecPolicyChange(void)
101101
leader.Get<MeshCoP::ActiveDatasetManager>().SaveLocal(datasetInfo);
102102
}
103103

104-
// Wait for the dataset to propagate to the router.
105-
nexus.AdvanceTime(500);
104+
// Wait for the dataset to propagate and be processed.
105+
nexus.AdvanceTime(5 * Time::kOneSecondInMsec);
106106

107107
VerifyOrQuit(leader.Get<Mle::Mle>().IsLeader());
108-
VerifyOrQuit(router.Get<Mle::Mle>().IsRouter());
109108

110-
Log("Leader should take at least 10 seconds before downgrading");
111-
112-
nexus.AdvanceTime(5 * Time::kOneSecondInMsec);
113-
VerifyOrQuit(leader.Get<Mle::Mle>().IsLeader());
109+
// We check that security policy is propagated to and applied on
110+
// leader and router. This means `IsRouterRoleAllowed()` should be
111+
// false on both.
114112
VerifyOrQuit(!leader.Get<Mle::Mle>().IsRouterRoleAllowed());
115113
VerifyOrQuit(!router.Get<Mle::Mle>().IsRouterRoleAllowed());
116114

115+
Log("Leader should stay as leader for at least 10 seconds");
116+
VerifyOrQuit(leader.Get<Mle::Mle>().IsLeader());
117+
117118
Log("---------------------------------------------------------------------------------------");
118119
Log("Change back security policy. This should cancel the ongoing downgrade delay");
119120

@@ -170,14 +171,19 @@ void TestRouterDowngradeOnSecPolicyChange(void)
170171
leader.Get<MeshCoP::ActiveDatasetManager>().SaveLocal(datasetInfo);
171172
}
172173

173-
nexus.AdvanceTime(500);
174+
// Wait for the dataset to propagate and be processed.
175+
nexus.AdvanceTime(5 * Time::kOneSecondInMsec);
176+
174177
VerifyOrQuit(leader.Get<Mle::Mle>().IsLeader());
175178

176-
Log("Leader should take at least 10 seconds before downgrading");
179+
// We check that security policy is propagated to and applied on
180+
// leader and router. This means `IsRouterRoleAllowed()` should be
181+
// false on both.
182+
VerifyOrQuit(!leader.Get<Mle::Mle>().IsRouterRoleAllowed());
183+
VerifyOrQuit(!router.Get<Mle::Mle>().IsRouterRoleAllowed());
177184

178-
nexus.AdvanceTime(5 * Time::kOneSecondInMsec);
185+
Log("Leader should stay as leader for at least 10 seconds");
179186
VerifyOrQuit(leader.Get<Mle::Mle>().IsLeader());
180-
VerifyOrQuit(!leader.Get<Mle::Mle>().IsRouterRoleAllowed());
181187

182188
Log("Make sure both leader and router are downgraded and are now `detached`.");
183189

0 commit comments

Comments
 (0)