diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-01-25 15:45:26 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-01-27 20:48:42 +0900 |
commit | af61e847ce5199c292570e13cc695ed164cb8421 (patch) | |
tree | 27b3c854d4ca5cd58d05ecf8cea8bb6ce0417e91 /test/lib | |
parent | f5b79f84744ec53a9457c0f610dfde0581d5d4be (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/lib')
-rw-r--r-- | test/lib/base.py | 12 |
1 files changed, 12 insertions, 0 deletions
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') |