From af61e847ce5199c292570e13cc695ed164cb8421 Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Thu, 25 Jan 2018 15:45:26 +0900 Subject: 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 --- test/lib/base.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/lib') diff --git a/test/lib/base.py b/test/lib/base.py index c7afba6d..657c9623 100644 --- a/test/lib/base.py +++ b/test/lib/base.py @@ -123,6 +123,18 @@ def try_several_times(f, t=3, s=1): raise e +def assert_several_times(f, t=30, s=1): + e = AssertionError + for _ in range(t): + try: + f() + except AssertionError as e: + time.sleep(s) + else: + return + raise e + + def get_bridges(): return try_several_times(lambda: local("docker network ls | awk 'NR > 1{print $2}'", capture=True)).split('\n') -- cgit v1.2.3