diff options
| author | Ilya Shakhat <shakhat@gmail.com> | 2017-10-25 17:30:53 +0200 |
|---|---|---|
| committer | Ilya Shakhat <shakhat@gmail.com> | 2017-11-08 08:56:17 +0100 |
| commit | 71589dd64f4391afba0bfe28c2263dfd43a6950e (patch) | |
| tree | 74f8f6f638b5010aa42806ecc1daea81d7350e05 /osprofiler | |
| parent | ffd8d7d51b0fbfb0abe99671277b06dd888b4903 (diff) | |
| download | osprofiler-71589dd64f4391afba0bfe28c2263dfd43a6950e.tar.gz | |
Add Zuul job for functional testing
The job prepares VM with RabbitMQ installed, then it executes tests
located under osprofiler/tests/functional.
To run the job manually use `tox -e functional` or
`tox -e functional-py35`.
Change-Id: I1f2b99737d1f17bb09662dc24c4858a1a7a1ad44
Diffstat (limited to 'osprofiler')
| -rw-r--r-- | osprofiler/tests/functional/config.cfg | 2 | ||||
| -rw-r--r-- | osprofiler/tests/functional/test_driver.py | 47 | ||||
| -rw-r--r-- | osprofiler/tests/test.py | 11 |
3 files changed, 42 insertions, 18 deletions
diff --git a/osprofiler/tests/functional/config.cfg b/osprofiler/tests/functional/config.cfg index d1d1e49..32219ad 100644 --- a/osprofiler/tests/functional/config.cfg +++ b/osprofiler/tests/functional/config.cfg @@ -1,3 +1,5 @@ +[DEFAULT] +transport_url=rabbit://localhost:5672/ [profiler] connection_string="messaging://" diff --git a/osprofiler/tests/functional/test_driver.py b/osprofiler/tests/functional/test_driver.py index 6b4bcb8..7a5d721 100644 --- a/osprofiler/tests/functional/test_driver.py +++ b/osprofiler/tests/functional/test_driver.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import logging import os from oslo_config import cfg @@ -25,9 +26,19 @@ from osprofiler.tests import test CONF = cfg.CONF +LOG = logging.getLogger(__name__) -class DriverTestCase(test.TestCase): +@profiler.trace_cls("rpc", hide_args=True) +class Foo(object): + def bar(self, x): + return self.baz(x, x) + + def baz(self, x, y): + return x * y + + +class DriverTestCase(test.FunctionalTestCase): SERVICE = "service" PROJECT = "project" @@ -40,15 +51,6 @@ class DriverTestCase(test.TestCase): trace_sqlalchemy=False, hmac_keys="SECRET_KEY") - @profiler.trace_cls("rpc", hide_args=True) - class Foo(object): - - def bar(self, x): - return self.baz(x, x) - - def baz(self, x, y): - return x * y - def _assert_dict(self, info, **kwargs): for key in kwargs: self.assertEqual(kwargs[key], info[key]) @@ -75,26 +77,35 @@ class DriverTestCase(test.TestCase): self._assert_dict(raw_stop, **exp_raw) def test_get_report(self): + # initialize profiler notifier (the same way as in services) initializer.init_from_conf( - CONF, None, self.PROJECT, self.SERVICE, "host") + CONF, {}, self.PROJECT, self.SERVICE, "host") profiler.init("SECRET_KEY") - foo = DriverTestCase.Foo() + # grab base_id + base_id = profiler.get().get_base_id() + + # execute profiled code + foo = Foo() foo.bar(1) + # instantiate report engine (the same way as in osprofiler CLI) engine = base.get_driver(CONF.profiler.connection_string, project=self.PROJECT, service=self.SERVICE, host="host", conf=CONF) - base_id = profiler.get().get_base_id() - res = engine.get_report(base_id) - self.assertEqual("total", res["info"]["name"]) - self.assertEqual(2, res["stats"]["rpc"]["count"]) - self.assertEqual(1, len(res["children"])) + # generate the report + report = engine.get_report(base_id) + LOG.debug("OSProfiler report: %s", report) + + # verify the report + self.assertEqual("total", report["info"]["name"]) + self.assertEqual(2, report["stats"]["rpc"]["count"]) + self.assertEqual(1, len(report["children"])) - cbar = res["children"][0] + cbar = report["children"][0] self._assert_child_dict( cbar, base_id, base_id, "rpc", "osprofiler.tests.functional.test_driver.Foo.bar") diff --git a/osprofiler/tests/test.py b/osprofiler/tests/test.py index fd337c9..3e86542 100644 --- a/osprofiler/tests/test.py +++ b/osprofiler/tests/test.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +import logging +import sys from testtools import testcase @@ -20,3 +22,12 @@ from testtools import testcase class TestCase(testcase.TestCase): """Test case base class for all osprofiler unit tests.""" pass + + +class FunctionalTestCase(TestCase): + """Base for functional tests""" + + def setUp(self): + super(FunctionalTestCase, self).setUp() + + logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) |
