From 09fc6b561901a06551cd9e32cd7bf58d1cf25662 Mon Sep 17 00:00:00 2001 From: Hua Liu <58683130+liuh-80@users.noreply.github.com> Date: Wed, 9 Oct 2024 06:10:15 +0800 Subject: [PATCH] Fix the issue where the test case randomly fails due to not waiting after updating the config DB. (#3305) * Fix the issue where the test case randomly fails due to not waiting after updating the config DB. Why I did it Some test case randomly fails due to not waiting after updating the config DB. --- tests/dash/dash_db.py | 3 +++ tests/dash/test_dash_acl.py | 2 ++ tests/dvslib/dvs_hash.py | 2 ++ tests/test_ipv6_link_local.py | 4 ++-- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/dash/dash_db.py b/tests/dash/dash_db.py index 1cbd19eeff..a26e0b5091 100644 --- a/tests/dash/dash_db.py +++ b/tests/dash/dash_db.py @@ -2,6 +2,7 @@ from dvslib.dvs_common import wait_for_result import typing import pytest +import time from dash_api.appliance_pb2 import * from dash_api.vnet_pb2 import * @@ -58,9 +59,11 @@ def __setitem__(self, key: str, pairs: typing.Union[dict, list, tuple]): for k, v in pairs: pairs_str.append((to_string(k), to_string(v))) self.set(key, pairs_str) + time.sleep(1) def __delitem__(self, key: str): self.delete(str(key)) + time.sleep(1) class Table(swsscommon.Table): diff --git a/tests/dash/test_dash_acl.py b/tests/dash/test_dash_acl.py index c85fbf532b..46c720fa4e 100644 --- a/tests/dash/test_dash_acl.py +++ b/tests/dash/test_dash_acl.py @@ -87,10 +87,12 @@ def __setitem__(self, key: str, pairs: Union[dict, list, tuple]): pairs_str.append((to_string(k), to_string(v))) self.table.set(key, pairs_str) self.keys.add(key) + time.sleep(1) def __delitem__(self, key: str): self.table.delete(str(key)) self.keys.discard(key) + time.sleep(1) def get_keys(self): return self.keys diff --git a/tests/dvslib/dvs_hash.py b/tests/dvslib/dvs_hash.py index 5ac896962c..66f364b7e0 100644 --- a/tests/dvslib/dvs_hash.py +++ b/tests/dvslib/dvs_hash.py @@ -1,5 +1,6 @@ """Utilities for interacting with HASH objects when writing VS tests.""" from typing import Dict, List +import time class DVSHash: @@ -21,6 +22,7 @@ def update_switch_hash( ) -> None: """Update switch hash global in Config DB.""" self.config_db.update_entry(self.CDB_SWITCH_HASH, self.KEY_SWITCH_HASH_GLOBAL, qualifiers) + time.sleep(1) def get_hash_ids( self, diff --git a/tests/test_ipv6_link_local.py b/tests/test_ipv6_link_local.py index 048b8f2e17..642274c15d 100644 --- a/tests/test_ipv6_link_local.py +++ b/tests/test_ipv6_link_local.py @@ -59,10 +59,10 @@ def test_NeighborAddRemoveIpv6LinkLocal(self, dvs, testlog): time.sleep(2) # Neigh entries should contain Ipv6-link-local neighbors, should be 4 - neigh_entries = self.pdb.get_keys("NEIGH_TABLE") - assert (len(neigh_entries) == 4) + self.pdb.wait_for_n_keys("NEIGH_TABLE", 4) found_entry = False + neigh_entries = self.pdb.get_keys("NEIGH_TABLE") for key in neigh_entries: if (key.find("Ethernet4:2001::2") or key.find("Ethernet0:2000::2")): found_entry = True