"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "neutron/tests/unit/notifiers/test_batch_notifier.py" between
neutron-14.0.2.tar.gz and neutron-14.0.3.tar.gz

About: OpenStack Neutron (Core Service: Networking) enables network connectivity as a service for other OpenStack services, such as OpenStack Compute. Provides an API for users to define networks and the attachments into them. Has a pluggable architecture that supports many popular networking vendors and technologies.
The "Stein" series (maintained release).

test_batch_notifier.py  (neutron-14.0.2):test_batch_notifier.py  (neutron-14.0.3)
skipping to change at line 19 skipping to change at line 19
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# 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 eventlet import eventlet
import mock import mock
from neutron.common import utils
from neutron.notifiers import batch_notifier from neutron.notifiers import batch_notifier
from neutron.tests import base from neutron.tests import base
class TestBatchNotifier(base.BaseTestCase): class TestBatchNotifier(base.BaseTestCase):
def setUp(self): def setUp(self):
super(TestBatchNotifier, self).setUp() super(TestBatchNotifier, self).setUp()
self.notifier = batch_notifier.BatchNotifier(0.1, lambda x: x) self._received_events = eventlet.Queue()
self.spawn_n_p = mock.patch('eventlet.spawn_n') self.notifier = batch_notifier.BatchNotifier(2, self._queue_events)
self.spawn_n = self.spawn_n_p.start() self.spawn_n_p = mock.patch.object(eventlet, 'spawn_n')
def _queue_events(self, events):
for event in events:
self._received_events.put(event)
def test_queue_event_no_event(self): def test_queue_event_no_event(self):
spawn_n = self.spawn_n_p.start()
self.notifier.queue_event(None) self.notifier.queue_event(None)
self.assertEqual(0, len(self.notifier.pending_events)) self.assertEqual(0, len(self.notifier._pending_events.queue))
self.assertEqual(0, self.spawn_n.call_count) self.assertEqual(0, spawn_n.call_count)
def test_queue_event_first_event(self): def test_queue_event_first_event(self):
spawn_n = self.spawn_n_p.start()
self.notifier.queue_event(mock.Mock()) self.notifier.queue_event(mock.Mock())
self.assertEqual(1, len(self.notifier.pending_events)) self.assertEqual(1, len(self.notifier._pending_events.queue))
self.assertEqual(1, self.spawn_n.call_count) self.assertEqual(1, spawn_n.call_count)
def test_queue_event_multiple_events(self): def test_queue_event_multiple_events_notify_method(self):
self.spawn_n_p.stop() def _batch_notifier_dequeue():
c_mock = mock.patch.object(self.notifier, 'callback').start() while not self.notifier._pending_events.empty():
events = 6 self.notifier._pending_events.get()
for i in range(0, events):
self.notifier.queue_event(mock.Mock()) c_mock = mock.patch.object(self.notifier, '_notify',
side_effect=_batch_notifier_dequeue).start()
events = 20
for i in range(events):
self.notifier.queue_event('Event %s' % i)
eventlet.sleep(0) # yield to let coro execute eventlet.sleep(0) # yield to let coro execute
while self.notifier.pending_events: utils.wait_until_true(self.notifier._pending_events.empty,
# wait for coroutines to finish timeout=5)
eventlet.sleep(0.1) # Called twice: when the first thread calls "synced_send" and then,
# in the same loop, when self._pending_events is not empty(). All
# self.notifier.queue_event calls are done in just one
# "batch_interval" (2 secs).
self.assertEqual(2, c_mock.call_count) self.assertEqual(2, c_mock.call_count)
self.assertEqual(6, sum(len(c[0][0]) for c in c_mock.call_args_list))
self.assertEqual(0, len(self.notifier.pending_events))
def test_queue_event_call_send_events(self): def test_queue_event_multiple_events_callback_method(self):
with mock.patch.object(self.notifier, events = 20
'callback') as send_events: for i in range(events):
self.spawn_n.side_effect = lambda func: func() self.notifier.queue_event('Event %s' % i)
self.notifier.queue_event(mock.Mock()) eventlet.sleep(0) # yield to let coro execute
while self.notifier.pending_events:
# wait for coroutines to finish utils.wait_until_true(self.notifier._pending_events.empty,
eventlet.sleep(0.1) timeout=5)
self.assertTrue(send_events.called) expected = ['Event %s' % i for i in range(events)]
# Check the events have been handled in the same input order.
self.assertEqual(expected, list(self._received_events.queue))
 End of changes. 10 change blocks. 
18 lines changed or deleted 30 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)