diff --git a/ovn_bgp_agent/tests/utils.py b/ovn_bgp_agent/tests/utils.py index 95092411..568da161 100644 --- a/ovn_bgp_agent/tests/utils.py +++ b/ovn_bgp_agent/tests/utils.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -import eventlet +import time import uuid @@ -52,12 +52,12 @@ def wait_until_true(predicate, timeout=60, sleep=1, exception=None): :param exception: Exception instance to raise on timeout. If None is passed (default) then WaitTimeout exception is raised. """ - try: - with eventlet.Timeout(timeout): - while not predicate(): - eventlet.sleep(sleep) - except eventlet.Timeout: - if exception is not None: - # pylint: disable=raising-bad-type - raise exception - raise WaitTimeout('Timed out after %d seconds' % timeout) + start_time = time.time() + + while not predicate(): + elapsed_time = time.time() - start_time + if elapsed_time > timeout: + raise exception if exception else WaitTimeout( + _("Timed out after %d seconds") % timeout + ) + time.sleep(sleep)