Fix sporadic unit test failure
TestDriverListener.test_get_listener may fail if the serve_forever thread takes too long to start. Wait for up to 1 sec when checking that serve_forever was called. Story: 2010218 Task: 45965 Change-Id: Ib3f269cbe80222aafb22a36bb09444480a4bbb8d (cherry picked from commitf29d8aa118
) (cherry picked from commit64947c5f12
)
This commit is contained in:
parent
5311ab6c74
commit
9c8e5e0318
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
import errno
|
||||
import socket
|
||||
import time
|
||||
from unittest import mock
|
||||
|
||||
from oslo_config import cfg
|
||||
@ -29,6 +30,13 @@ class TestDriverListener(base.TestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
def _wait_until_called(self, mock_to_be_called):
|
||||
"""Wait for up to 1 sec for the given mock to be called."""
|
||||
for _ in range(10):
|
||||
if mock_to_be_called.call_count > 0:
|
||||
break
|
||||
time.sleep(.1)
|
||||
|
||||
@mock.patch('octavia.api.drivers.driver_agent.driver_listener.memoryview')
|
||||
def test_recv(self, mock_memoryview):
|
||||
# TEST_STRING len() is 15
|
||||
@ -308,6 +316,7 @@ class TestDriverListener(base.TestCase):
|
||||
mock_exit_event.is_set.side_effect = [False, False, False, False, True]
|
||||
|
||||
driver_listener.status_listener(mock_exit_event)
|
||||
self._wait_until_called(mock_server.serve_forever)
|
||||
mock_server.serve_forever.assert_called()
|
||||
self.assertEqual(2, mock_cleanup.call_count)
|
||||
|
||||
@ -327,6 +336,7 @@ class TestDriverListener(base.TestCase):
|
||||
mock_exit_event.is_set.side_effect = [False, False, False, False, True]
|
||||
|
||||
driver_listener.stats_listener(mock_exit_event)
|
||||
self._wait_until_called(mock_server.serve_forever)
|
||||
mock_server.serve_forever.assert_called()
|
||||
|
||||
@mock.patch('octavia.api.drivers.driver_agent.driver_listener.'
|
||||
@ -345,4 +355,5 @@ class TestDriverListener(base.TestCase):
|
||||
mock_exit_event.is_set.side_effect = [False, False, False, False, True]
|
||||
|
||||
driver_listener.get_listener(mock_exit_event)
|
||||
self._wait_until_called(mock_server.serve_forever)
|
||||
mock_server.serve_forever.assert_called()
|
||||
|
Loading…
Reference in New Issue
Block a user