summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Shakhat <shakhat@gmail.com>2017-10-25 17:30:53 +0200
committerIlya Shakhat <shakhat@gmail.com>2017-11-08 08:56:17 +0100
commit71589dd64f4391afba0bfe28c2263dfd43a6950e (patch)
tree74f8f6f638b5010aa42806ecc1daea81d7350e05
parentffd8d7d51b0fbfb0abe99671277b06dd888b4903 (diff)
downloadosprofiler-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
-rw-r--r--.zuul.yaml10
-rw-r--r--bindep.txt1
-rw-r--r--osprofiler/tests/functional/config.cfg2
-rw-r--r--osprofiler/tests/functional/test_driver.py47
-rw-r--r--osprofiler/tests/test.py11
-rw-r--r--tox.ini1
6 files changed, 54 insertions, 18 deletions
diff --git a/.zuul.yaml b/.zuul.yaml
new file mode 100644
index 0000000..30e9c96
--- /dev/null
+++ b/.zuul.yaml
@@ -0,0 +1,10 @@
+- project:
+ name: openstack/osprofiler
+ check:
+ jobs:
+ - openstack-tox-functional
+ - openstack-tox-functional-py35
+ gate:
+ jobs:
+ - openstack-tox-functional
+ - openstack-tox-functional-py35
diff --git a/bindep.txt b/bindep.txt
new file mode 100644
index 0000000..f9d5f93
--- /dev/null
+++ b/bindep.txt
@@ -0,0 +1 @@
+rabbitmq-server [test]
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)
diff --git a/tox.ini b/tox.ini
index 8929336..8d33520 100644
--- a/tox.ini
+++ b/tox.ini
@@ -21,6 +21,7 @@ basepython = python2.7
setenv = {[testenv]setenv}
OS_TEST_PATH=./osprofiler/tests/functional
deps = {[testenv]deps}
+ oslo.messaging
[testenv:functional-py35]
basepython = python3.5