mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-14 06:12:32 +00:00
tests: remove reliance on time.sleep
Use proper retry loop to wait for state to converge, not some arbitrary delay. fixes #15878 Signed-off-by: Christian Hopps <chopps@labn.net>
This commit is contained in:
parent
2130575b8c
commit
727633a046
@ -62,7 +62,8 @@ def disable_debug(router):
|
||||
router.vtysh_cmd("no debug northbound callbacks configuration")
|
||||
|
||||
|
||||
def do_oper_test(tgen, query_results):
|
||||
@retry(retry_timeout=30, initial_wait=1)
|
||||
def _do_oper_test(tgen, qr):
|
||||
r1 = tgen.gears["r1"].net
|
||||
|
||||
qcmd = (
|
||||
@ -73,50 +74,55 @@ def do_oper_test(tgen, query_results):
|
||||
r"""| sed -e 's/"if-index": [0-9][0-9]*/"if-index": "rubout"/'"""
|
||||
r"""| sed -e 's/"id": [0-9][0-9]*/"id": "rubout"/'"""
|
||||
)
|
||||
|
||||
doreset = True
|
||||
# Don't use this for now.
|
||||
dd_json_cmp = None
|
||||
for qr in query_results:
|
||||
step(f"Perform query '{qr[0]}'", reset=doreset)
|
||||
if doreset:
|
||||
doreset = False
|
||||
expected = open(qr[1], encoding="ascii").read()
|
||||
output = r1.cmd_nostatus(qcmd.format(qr[0], qr[2] if len(qr) > 2 else ""))
|
||||
|
||||
try:
|
||||
ojson = json.loads(output)
|
||||
except json.decoder.JSONDecodeError as error:
|
||||
logging.error("Error decoding json: %s\noutput:\n%s", error, output)
|
||||
raise
|
||||
expected = open(qr[1], encoding="ascii").read()
|
||||
output = r1.cmd_nostatus(qcmd.format(qr[0], qr[2] if len(qr) > 2 else ""))
|
||||
|
||||
try:
|
||||
ejson = json.loads(expected)
|
||||
except json.decoder.JSONDecodeError as error:
|
||||
logging.error(
|
||||
"Error decoding json exp result: %s\noutput:\n%s", error, expected
|
||||
try:
|
||||
ojson = json.loads(output)
|
||||
except json.decoder.JSONDecodeError as error:
|
||||
logging.error("Error decoding json: %s\noutput:\n%s", error, output)
|
||||
raise
|
||||
|
||||
try:
|
||||
ejson = json.loads(expected)
|
||||
except json.decoder.JSONDecodeError as error:
|
||||
logging.error(
|
||||
"Error decoding json exp result: %s\noutput:\n%s", error, expected
|
||||
)
|
||||
raise
|
||||
|
||||
if dd_json_cmp:
|
||||
cmpout = json_cmp(ojson, ejson, exact_match=True)
|
||||
if cmpout:
|
||||
logging.warning(
|
||||
"-------DIFF---------\n%s\n---------DIFF----------",
|
||||
pprint.pformat(cmpout),
|
||||
)
|
||||
else:
|
||||
cmpout = tt_json_cmp(ojson, ejson, exact=True)
|
||||
if cmpout:
|
||||
logging.warning(
|
||||
"-------EXPECT--------\n%s\n------END-EXPECT------",
|
||||
json.dumps(ejson, indent=4),
|
||||
)
|
||||
logging.warning(
|
||||
"--------GOT----------\n%s\n-------END-GOT--------",
|
||||
json.dumps(ojson, indent=4),
|
||||
)
|
||||
raise
|
||||
|
||||
if dd_json_cmp:
|
||||
cmpout = json_cmp(ojson, ejson, exact_match=True)
|
||||
if cmpout:
|
||||
logging.warning(
|
||||
"-------DIFF---------\n%s\n---------DIFF----------",
|
||||
pprint.pformat(cmpout),
|
||||
)
|
||||
else:
|
||||
cmpout = tt_json_cmp(ojson, ejson, exact=True)
|
||||
if cmpout:
|
||||
logging.warning(
|
||||
"-------EXPECT--------\n%s\n------END-EXPECT------",
|
||||
json.dumps(ejson, indent=4),
|
||||
)
|
||||
logging.warning(
|
||||
"--------GOT----------\n%s\n-------END-GOT--------",
|
||||
json.dumps(ojson, indent=4),
|
||||
)
|
||||
assert cmpout is None
|
||||
|
||||
assert cmpout is None
|
||||
|
||||
def do_oper_test(tgen, query_results):
|
||||
reset = True
|
||||
for qr in query_results:
|
||||
step(f"Perform query '{qr[0]}'", reset=reset)
|
||||
if reset:
|
||||
reset = False
|
||||
_do_oper_test(tgen, qr)
|
||||
|
||||
|
||||
def get_ip_networks(super_prefix, count):
|
||||
|
@ -95,7 +95,6 @@ def test_oper(tgen):
|
||||
check_kernel_32(r1, "12.12.12.12", 1, "")
|
||||
check_kernel_32(r1, "13.13.13.13", 1, "red")
|
||||
check_kernel_32(r1, "14.14.14.14", 1, "red")
|
||||
time.sleep(2)
|
||||
do_oper_test(tgen, query_results)
|
||||
|
||||
|
||||
|
@ -52,7 +52,6 @@ def test_oper_simple(tgen):
|
||||
|
||||
r1 = tgen.gears["r1"].net
|
||||
|
||||
time.sleep(2)
|
||||
count = 20 * 1000
|
||||
|
||||
vrf = None # "red"
|
||||
|
Loading…
Reference in New Issue
Block a user