Fix the flasky test test_submit_second_while_delaying_first

This test failied a few times and most recent faaailure is
- https://review.opendev.org/c/openstack/nova/+/975586 (PS8 run)

Traceback (most recent call last):
  File "/home/zuul/src/opendev.org/openstack/nova/nova/tests/unit/test_utils.py", line 2185, in test_submit_second_while_delaying_first
    self.assertGreater(task2_runtime, 2.0)
  File "/usr/lib/python3.12/unittest/case.py", line 1269, in assertGreater
    self.fail(self._formatMessage(msg, standardMsg))
  File "/usr/lib/python3.12/unittest/case.py", line 715, in fail
    raise self.failureException(msg)
AssertionError: 1.997275639999998 not greater than 2.0

From error, it seems we are capturing the start time after we
submit the task to executor who will count the task submit time
little ahead of test captured the task start time.

let's capture the task start time before task is submitted so that
we can caompare the time in more correct way.

Change-Id: I5a9845813b614c58e0f5a66e07f8a8c732f38eb3
Signed-off-by: Ghanshyam Maan <gmaan.os14@gmail.com>
This commit is contained in:
Ghanshyam Maan
2026-02-19 19:06:07 +00:00
parent 7dd05b7af6
commit b5c0a97582
+2 -2
View File
@@ -2154,8 +2154,8 @@ class StaticallyDelayingCancellableTaskExecutorWrapperTest(test.NoDBTestCase):
2, utils._get_default_executor())
self.addCleanup(executor.shutdown, wait=True)
future1 = executor.submit_with_delay(task1)
task1_start = time.monotonic()
future1 = executor.submit_with_delay(task1)
# wait a bit so the wrapper is picking it up and waiting for its
# deadline
time.sleep(1)
@@ -2163,8 +2163,8 @@ class StaticallyDelayingCancellableTaskExecutorWrapperTest(test.NoDBTestCase):
self.assertFalse(task1_started.is_set())
# now submit the second task, it will be queued
future2 = executor.submit_with_delay(task2)
task2_start = time.monotonic()
future2 = executor.submit_with_delay(task2)
self.assertFalse(executor._queue.empty())
self.assertFalse(task1_started.is_set())