From d9b0b54ec3fbaebabc35b483eae1adfc812a7c25 Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Thu, 14 Aug 2025 07:46:41 -0400 Subject: [PATCH] Adapt wait_until_true The code is copy&pasted from Neutron tree. This patch copies what the Neutron patch [1] removing eventlet from wait_until_true does. [1] https://review.opendev.org/c/openstack/neutron/+/937843 Change-Id: Ib8caf3140aed22da40bbe48518df5a1ca2ecf8d1 Signed-off-by: Jakub Libosvar --- ovn_bgp_agent/tests/utils.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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)