summaryrefslogtreecommitdiffhomepage
path: root/test/scenario_test/bgp_router_test.py
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-01-25 15:45:26 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-01-27 20:48:42 +0900
commitaf61e847ce5199c292570e13cc695ed164cb8421 (patch)
tree27b3c854d4ca5cd58d05ecf8cea8bb6ce0417e91 /test/scenario_test/bgp_router_test.py
parentf5b79f84744ec53a9457c0f610dfde0581d5d4be (diff)
scenario_test: Enable to try assertion several times
Some times, on Travis-CI, some test cases fail unexpectedly in checking paths in RIBs due to advertisements are not yet received from other routers. Currently, in order to avoid this unexpected result, "time.sleep" is inserted after adding new routes, but it is not enough. This patch introduces a new function to enable to do assertion several times and avoid failure with the first assertion. Note: This patch does not introduces this change into all test cases, do only into some test cases which fail relatively frequently. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'test/scenario_test/bgp_router_test.py')
-rw-r--r--test/scenario_test/bgp_router_test.py32
1 files changed, 18 insertions, 14 deletions
diff --git a/test/scenario_test/bgp_router_test.py b/test/scenario_test/bgp_router_test.py
index 7d93ba53..727c598e 100644
--- a/test/scenario_test/bgp_router_test.py
+++ b/test/scenario_test/bgp_router_test.py
@@ -33,6 +33,7 @@ from lib.base import (
BGP_ATTR_TYPE_MULTI_EXIT_DISC,
BGP_ATTR_TYPE_LOCAL_PREF,
wait_for_completion,
+ assert_several_times,
)
from lib.gobgp import (
GoBGPContainer,
@@ -312,17 +313,17 @@ class GoBGPTestBase(unittest.TestCase):
self.test_02_check_gobgp_global_rib()
paths = q1.get_global_rib('20.0.0.0/24')
- self.assertTrue(len(paths) == 1)
+ self.assertEqual(len(paths), 1)
n_addrs = [i[1].split('/')[0] for i in self.gobgp.ip_addrs]
- self.assertTrue(paths[0]['nexthop'] in n_addrs)
+ self.assertIn(paths[0]['nexthop'], n_addrs)
q3.stop()
- time.sleep(3)
+ self.gobgp.wait_for(expected_state=BGP_FSM_ACTIVE, peer=q3)
paths = q1.get_global_rib('20.0.0.0/24')
- self.assertTrue(len(paths) == 1)
- self.assertTrue(paths[0]['nexthop'] in n_addrs)
+ self.assertEqual(len(paths), 1)
+ self.assertIn(paths[0]['nexthop'], n_addrs)
g1.del_peer(q3)
del self.quaggas['q3']
@@ -340,19 +341,22 @@ class GoBGPTestBase(unittest.TestCase):
self.test_02_check_gobgp_global_rib()
paths = g1.get_adj_rib_out(q1, '30.0.0.0/24')
- self.assertTrue(len(paths) == 1)
- self.assertTrue('source-id' not in paths[0])
+ self.assertEqual(len(paths), 1)
+ self.assertNotIn('source-id', paths[0])
paths = g1.get_adj_rib_out(q2, '30.0.0.0/24')
- self.assertTrue(len(paths) == 1)
- self.assertTrue('source-id' not in paths[0])
+ self.assertEqual(len(paths), 1)
+ self.assertNotIn('source-id', paths[0])
g1.local('gobgp global rib del 30.0.0.0/24')
- paths = g1.get_adj_rib_out(q1, '30.0.0.0/24')
- self.assertTrue(len(paths) == 0)
- paths = g1.get_adj_rib_out(q2, '30.0.0.0/24')
- self.assertTrue(len(paths) == 1)
- self.assertTrue(paths[0]['source-id'] == '192.168.0.2')
+ def f():
+ paths = g1.get_adj_rib_out(q1, '30.0.0.0/24')
+ self.assertEqual(len(paths), 0)
+ paths = g1.get_adj_rib_out(q2, '30.0.0.0/24')
+ self.assertEqual(len(paths), 1)
+ self.assertEqual(paths[0]['source-id'], '192.168.0.2')
+
+ assert_several_times(f)
def test_19_check_grpc_add_neighbor(self):
g1 = self.gobgp