From 8b842d39a64df863def0b92519090f4c028e8670 Mon Sep 17 00:00:00 2001 From: Simon Lin Date: Fri, 11 Sep 2020 23:56:53 +0800 Subject: [PATCH] [scripts] fix test_router_reattach (#5517) Fix test_router_attach.py failing by a small chance. Root cause: routerdowngradethreshold restored back to default (23) after node reset, so the test had 5/120 chance to downgrade. We should set it back to 32 before starting it. This commit also enhances the test for a little bit: - Make sure the node reattached as Router within 1 second - Make sure the node does not downgrade after Router Selection Jitter (3s) --- tests/scripts/thread-cert/node.py | 4 ++++ tests/scripts/thread-cert/test_router_reattach.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/tests/scripts/thread-cert/node.py b/tests/scripts/thread-cert/node.py index ac113182f..fd4092668 100755 --- a/tests/scripts/thread-cert/node.py +++ b/tests/scripts/thread-cert/node.py @@ -771,6 +771,10 @@ class Node: self.send_command(cmd) self._expect('Done') + def get_router_downgrade_threshold(self) -> int: + self.send_command('routerdowngradethreshold') + return int(self._expect_result(r'\d+')) + def prefer_router_id(self, router_id): cmd = 'preferrouterid %d' % router_id self.send_command(cmd) diff --git a/tests/scripts/thread-cert/test_router_reattach.py b/tests/scripts/thread-cert/test_router_reattach.py index 690c62d25..7ab7132c6 100755 --- a/tests/scripts/thread-cert/test_router_reattach.py +++ b/tests/scripts/thread-cert/test_router_reattach.py @@ -272,7 +272,16 @@ class test_router_reattach(thread_cert.TestCase): self.assertEqual(self.nodes[i].get_state(), 'router') self.nodes[2].reset() + self.nodes[2].set_router_selection_jitter(3) + self.nodes[2].set_router_upgrade_threshold(32) + self.nodes[2].set_router_downgrade_threshold(32) + self.nodes[2].start() + self.assertEqual(self.nodes[2].get_router_downgrade_threshold(), 32) + # Verify that the node restored as Router. + self.simulator.go(1) + self.assertEqual(self.nodes[2].get_state(), 'router') + # Verify that the node does not downgrade after Router Selection Jitter. self.simulator.go(5) self.assertEqual(self.nodes[2].get_state(), 'router')