Remove eventlet.sleep(0) in collector tests
This change removes eventlet.sleep(0) in collector tests Change-Id: I72df104720c4c0b6cf41adfcafea0c769e872953 Closes-bug: #1312826
This commit is contained in:
parent
ad72ca88ab
commit
4f958acbff
@ -15,9 +15,9 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
import contextlib
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
import eventlet
|
|
||||||
import mock
|
import mock
|
||||||
import msgpack
|
import msgpack
|
||||||
import oslo.messaging
|
import oslo.messaging
|
||||||
@ -159,18 +159,22 @@ class TestCollector(tests_base.BaseTestCase):
|
|||||||
|
|
||||||
self._verify_udp_socket(udp_socket)
|
self._verify_udp_socket(udp_socket)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _dummy_thread_group_add_thread(method):
|
||||||
|
method()
|
||||||
|
|
||||||
@mock.patch.object(oslo.messaging.MessageHandlingServer, 'start')
|
@mock.patch.object(oslo.messaging.MessageHandlingServer, 'start')
|
||||||
@mock.patch.object(collector.CollectorService, 'start_udp')
|
@mock.patch.object(collector.CollectorService, 'start_udp')
|
||||||
def test_only_udp(self, udp_start, rpc_start):
|
def test_only_udp(self, udp_start, rpc_start):
|
||||||
"""Check that only UDP is started if rpc_backend is empty."""
|
"""Check that only UDP is started if rpc_backend is empty."""
|
||||||
self.CONF.set_override('rpc_backend', '')
|
self.CONF.set_override('rpc_backend', '')
|
||||||
udp_socket = self._make_fake_socket(self.counter)
|
udp_socket = self._make_fake_socket(self.counter)
|
||||||
with mock.patch('socket.socket', return_value=udp_socket):
|
with contextlib.nested(
|
||||||
|
mock.patch.object(
|
||||||
|
self.srv.tg, 'add_thread',
|
||||||
|
side_effect=self._dummy_thread_group_add_thread),
|
||||||
|
mock.patch('socket.socket', return_value=udp_socket)):
|
||||||
self.srv.start()
|
self.srv.start()
|
||||||
|
|
||||||
# UDP run into its own thread, so we need to sleep to get
|
|
||||||
# the thread start
|
|
||||||
eventlet.sleep(0)
|
|
||||||
self.assertEqual(0, rpc_start.call_count)
|
self.assertEqual(0, rpc_start.call_count)
|
||||||
self.assertEqual(1, udp_start.call_count)
|
self.assertEqual(1, udp_start.call_count)
|
||||||
|
|
||||||
@ -179,10 +183,10 @@ class TestCollector(tests_base.BaseTestCase):
|
|||||||
def test_only_rpc(self, udp_start, rpc_start):
|
def test_only_rpc(self, udp_start, rpc_start):
|
||||||
"""Check that only RPC is started if udp_address is empty."""
|
"""Check that only RPC is started if udp_address is empty."""
|
||||||
self.CONF.set_override('udp_address', '', group='collector')
|
self.CONF.set_override('udp_address', '', group='collector')
|
||||||
|
with mock.patch.object(
|
||||||
|
self.srv.tg, 'add_thread',
|
||||||
|
side_effect=self._dummy_thread_group_add_thread):
|
||||||
self.srv.start()
|
self.srv.start()
|
||||||
# UDP run into its own thread, so we need to sleep to get
|
|
||||||
# the thread start
|
|
||||||
eventlet.sleep(0)
|
|
||||||
self.assertEqual(1, rpc_start.call_count)
|
self.assertEqual(1, rpc_start.call_count)
|
||||||
self.assertEqual(0, udp_start.call_count)
|
self.assertEqual(0, udp_start.call_count)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user