summaryrefslogtreecommitdiff
path: root/osprofiler/tests
diff options
context:
space:
mode:
authorVipin Balachandran <vbala@vmware.com>2016-11-23 19:42:24 +0530
committerVipin Balachandran <vbala@vmware.com>2016-12-15 19:36:35 +0530
commit899f4138c74a450dfb283485e9cd5357492b46fc (patch)
tree14d8569ab02dccb747b5fdf5cc7c91f1284f8a94 /osprofiler/tests
parent33f85b2046e59deadc724eb28b7ce1b4487a5a5e (diff)
downloadosprofiler-899f4138c74a450dfb283485e9cd5357492b46fc.tar.gz
Add functional test for notifier backend
We have several notifier backends now. It is important to verify that they are not broken when changes are made. Adding a test for notifier backend verification. We can use this test to verify the backends against each osprofiler patch. Note: the support for messaging/ceilometer backend will be added in a subsequent patch. Change-Id: Icb0f453de30dbfa1a7a990e73391cf17a246e9bb
Diffstat (limited to 'osprofiler/tests')
-rw-r--r--osprofiler/tests/functional/__init__.py0
-rw-r--r--osprofiler/tests/functional/config.cfg3
-rw-r--r--osprofiler/tests/functional/test_driver.py110
3 files changed, 113 insertions, 0 deletions
diff --git a/osprofiler/tests/functional/__init__.py b/osprofiler/tests/functional/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/osprofiler/tests/functional/__init__.py
diff --git a/osprofiler/tests/functional/config.cfg b/osprofiler/tests/functional/config.cfg
new file mode 100644
index 0000000..d1d1e49
--- /dev/null
+++ b/osprofiler/tests/functional/config.cfg
@@ -0,0 +1,3 @@
+
+[profiler]
+connection_string="messaging://"
diff --git a/osprofiler/tests/functional/test_driver.py b/osprofiler/tests/functional/test_driver.py
new file mode 100644
index 0000000..6a1b020
--- /dev/null
+++ b/osprofiler/tests/functional/test_driver.py
@@ -0,0 +1,110 @@
+# Copyright (c) 2016 VMware, Inc.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import os
+
+from oslo_config import cfg
+
+from osprofiler.drivers import base
+from osprofiler import initializer
+from osprofiler import opts
+from osprofiler import profiler
+from osprofiler.tests import test
+
+
+CONF = cfg.CONF
+
+
+class DriverTestCase(test.TestCase):
+
+ SERVICE = "service"
+ PROJECT = "project"
+
+ def setUp(self):
+ super(DriverTestCase, self).setUp()
+ CONF(["--config-file", os.path.dirname(__file__) + "/config.cfg"])
+ opts.set_defaults(CONF,
+ enabled=True,
+ 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])
+
+ def _assert_child_dict(self, child, base_id, parent_id, name, fn_name):
+ self.assertEqual(parent_id, child["parent_id"])
+
+ exp_info = {"name": "rpc",
+ "service": self.SERVICE,
+ "project": self.PROJECT}
+ self._assert_dict(child["info"], **exp_info)
+
+ exp_raw_info = {"project": self.PROJECT,
+ "service": self.SERVICE}
+ raw_start = child["info"]["meta.raw_payload.%s-start" % name]
+ self._assert_dict(raw_start["info"], **exp_raw_info)
+ self.assertEqual(fn_name, raw_start["info"]["function"]["name"])
+ exp_raw = {"name": "%s-start" % name,
+ "service": self.SERVICE,
+ "trace_id": child["trace_id"],
+ "project": self.PROJECT,
+ "base_id": base_id}
+ self._assert_dict(raw_start, **exp_raw)
+
+ raw_stop = child["info"]["meta.raw_payload.%s-stop" % name]
+ self._assert_dict(raw_stop["info"], **exp_raw_info)
+ exp_raw["name"] = "%s-stop" % name
+ self._assert_dict(raw_stop, **exp_raw)
+
+ def test_get_report(self):
+ initializer.init_from_conf(
+ CONF, None, self.PROJECT, self.SERVICE, "host")
+ profiler.init("SECRET_KEY", project=self.PROJECT, service=self.SERVICE)
+
+ foo = DriverTestCase.Foo()
+ foo.bar(1)
+
+ 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"]))
+
+ cbar = res["children"][0]
+ self._assert_child_dict(
+ cbar, base_id, base_id, "rpc",
+ "osprofiler.tests.functional.test_driver.Foo.bar")
+
+ self.assertEqual(1, len(cbar["children"]))
+ cbaz = cbar["children"][0]
+ self._assert_child_dict(
+ cbaz, base_id, cbar["trace_id"], "rpc",
+ "osprofiler.tests.functional.test_driver.Foo.baz")