Merge "Fixed unit test TestRealNotification"

This commit is contained in:
Jenkins 2014-06-10 11:02:40 +00:00 committed by Gerrit Code Review
commit 32b64b79cb

View File

@ -16,6 +16,7 @@
# under the License. # under the License.
"""Tests for Ceilometer notify daemon.""" """Tests for Ceilometer notify daemon."""
import eventlet.semaphore
import mock import mock
import oslo.messaging import oslo.messaging
@ -172,10 +173,14 @@ class TestRealNotification(tests_base.BaseTestCase):
pipeline = yaml.dump([{ pipeline = yaml.dump([{
'name': 'test_pipeline', 'name': 'test_pipeline',
'interval': 5, 'interval': 5,
'counters': ['*'], 'counters': ['instance', 'memory'],
'transformers': [], 'transformers': [],
'publishers': ['test://'], 'publishers': ['test://'],
}]) }])
self.expected_samples = 2
self.sem = eventlet.semaphore.Semaphore(0)
pipeline_cfg_file = fileutils.write_to_tempfile(content=pipeline, pipeline_cfg_file = fileutils.write_to_tempfile(content=pipeline,
prefix="pipeline", prefix="pipeline",
suffix="yaml") suffix="yaml")
@ -193,13 +198,17 @@ class TestRealNotification(tests_base.BaseTestCase):
fake_publisher = fake_publisher_cls.return_value fake_publisher = fake_publisher_cls.return_value
fake_publisher.publish_samples.side_effect = \ fake_publisher.publish_samples.side_effect = \
lambda *args: self.srv.stop() lambda *args: self.sem.release()
notifier = messaging.get_notifier("compute.vagrant-precise") notifier = messaging.get_notifier("compute.vagrant-precise")
notifier.info(context.RequestContext(), 'compute.instance.create.end', notifier.info(context.RequestContext(), 'compute.instance.create.end',
TEST_NOTICE_PAYLOAD) TEST_NOTICE_PAYLOAD)
# we should wait all the expected notification listeners finished
self.srv.listeners[0].wait() # processing the notification
for i in range(self.expected_samples):
self.sem.acquire(timeout=30)
# stop NotificationService
self.srv.stop()
class SamplesMatcher(object): class SamplesMatcher(object):
def __eq__(self, samples): def __eq__(self, samples):
@ -208,10 +217,6 @@ class TestRealNotification(tests_base.BaseTestCase):
return False return False
return True return True
fake_publisher.publish_samples.assert_has_calls([ fake_publisher.publish_samples.assert_has_calls(
mock.call(mock.ANY, SamplesMatcher()), [mock.call(mock.ANY, SamplesMatcher())] * self.expected_samples
mock.call(mock.ANY, SamplesMatcher()), )
mock.call(mock.ANY, SamplesMatcher()),
mock.call(mock.ANY, SamplesMatcher()),
mock.call(mock.ANY, SamplesMatcher()),
])