summaryrefslogtreecommitdiff
path: root/buildscripts/tests
diff options
context:
space:
mode:
authorRobert Guo <robert.guo@10gen.com>2018-02-28 13:01:21 -0500
committerRobert Guo <robert.guo@10gen.com>2018-03-12 16:22:26 -0400
commite372a6848385ec26aeeed4688d472348f87bc88f (patch)
treef42748dc48595bd222827449577e24ee5b7c5444 /buildscripts/tests
parent945167575f86cb4fba7c239cdd4264d2da30d4dc (diff)
downloadmongo-e372a6848385ec26aeeed4688d472348f87bc88f.tar.gz
SERVER-33202 add hook to generate data file for the perf dashboard
Diffstat (limited to 'buildscripts/tests')
-rw-r--r--buildscripts/tests/resmokelib/__init__.py0
-rw-r--r--buildscripts/tests/resmokelib/test_archival.py7
-rw-r--r--buildscripts/tests/resmokelib/testing/__init__.py0
-rw-r--r--buildscripts/tests/resmokelib/testing/hooks/__init__.py0
-rwxr-xr-xbuildscripts/tests/resmokelib/testing/hooks/test_combine_benchmark_results.py124
-rwxr-xr-xbuildscripts/tests/test_aws_ec2.py6
-rw-r--r--buildscripts/tests/test_fetch_test_lifecycle.py1
-rwxr-xr-xbuildscripts/tests/test_remote_operations.py5
8 files changed, 132 insertions, 11 deletions
diff --git a/buildscripts/tests/resmokelib/__init__.py b/buildscripts/tests/resmokelib/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/buildscripts/tests/resmokelib/__init__.py
diff --git a/buildscripts/tests/resmokelib/test_archival.py b/buildscripts/tests/resmokelib/test_archival.py
index bc36cdb4832..e8a6b73d832 100644
--- a/buildscripts/tests/resmokelib/test_archival.py
+++ b/buildscripts/tests/resmokelib/test_archival.py
@@ -2,19 +2,18 @@
""" Unit tests for archival. """
+from __future__ import absolute_import
+
import logging
import os
import random
import shutil
-import sys
import tempfile
import unittest
-
-if __name__ == "__main__" and __package__ is None:
- sys.path.append(os.getcwd())
from buildscripts.resmokelib.utils import archival
+
_BUCKET = "mongodatafiles"
diff --git a/buildscripts/tests/resmokelib/testing/__init__.py b/buildscripts/tests/resmokelib/testing/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/buildscripts/tests/resmokelib/testing/__init__.py
diff --git a/buildscripts/tests/resmokelib/testing/hooks/__init__.py b/buildscripts/tests/resmokelib/testing/hooks/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/buildscripts/tests/resmokelib/testing/hooks/__init__.py
diff --git a/buildscripts/tests/resmokelib/testing/hooks/test_combine_benchmark_results.py b/buildscripts/tests/resmokelib/testing/hooks/test_combine_benchmark_results.py
new file mode 100755
index 00000000000..1b07980f1fb
--- /dev/null
+++ b/buildscripts/tests/resmokelib/testing/hooks/test_combine_benchmark_results.py
@@ -0,0 +1,124 @@
+#!/usr/bin/env python
+
+from __future__ import absolute_import
+
+import datetime
+import unittest
+
+import mock
+
+import buildscripts.resmokelib.config as _config
+import buildscripts.resmokelib.testing.hooks.combine_benchmark_results as cbr
+
+_BM_CONTEXT = {
+ "date": "2018/01/30-18:40:25",
+ "num_cpus": 40,
+ "mhz_per_cpu": 4999,
+ "cpu_scaling_enabled": False,
+ "library_build_type": "debug"
+}
+
+_BM_REPORT = {
+ "name": "BM_Name/threads:10",
+ "iterations": 100,
+ "real_time": 202,
+ "cpu_time": 303,
+ "bytes_per_second": 404,
+ "items_per_second": 505,
+ "custom_counter_1": 606
+}
+
+_BM_MEDIAN_REPORT = {
+ "name": "BM_Name/threads:10_median",
+ "iterations": 100,
+ "real_time": 200,
+ "cpu_time": 300,
+ "bytes_per_second": 400,
+ "items_per_second": 500,
+ "custom_counter_1": 600
+}
+
+_BM_FULL_REPORT = {
+ "context": _BM_CONTEXT,
+ "benchmarks": [
+ _BM_REPORT,
+ _BM_MEDIAN_REPORT
+ ]
+}
+
+# 12/31/2999 @ 11:59pm (UTC)
+_START_TIME = 32503679999
+
+# 01/01/3000 @ 12:00am (UTC)
+_END_TIME = 32503680000
+
+
+class CombineBenchmarkResultsFixture(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ _config.EVERGREEN_REVISION = "evergreen_revision"
+ _config.EVERGREEN_PATCH_BUILD = False
+ _config.EVERGREEN_PROJECT_NAME = "evergreen_project_name"
+ _config.EVERGREEN_TASK_ID = "evergreen_task_id"
+ _config.EVERGREEN_TASK_NAME = "evergreen_task_name"
+ _config.EVERGREEN_VARIANT_NAME = "evergreen_variant_name"
+
+ # Mock the hook's parent class because we're testing only functionality of this hook and
+ # not anything related to or inherit from the parent class.
+ @mock.patch("buildscripts.resmokelib.testing.hooks.interface.Hook", autospec=True)
+ def setUp(self, MockHook):
+ self.bm_threads_report = cbr._BenchmarkThreadsReport(_BM_CONTEXT)
+
+ self.cbr_hook = cbr.CombineBenchmarkResults(None, None)
+
+ self.cbr_hook.create_time = datetime.datetime.utcfromtimestamp(_START_TIME)
+ self.cbr_hook.end_time = datetime.datetime.utcfromtimestamp(_END_TIME)
+ self.cbr_hook._parse_report(_BM_FULL_REPORT)
+
+
+class TestCombineBenchmarkResults(CombineBenchmarkResultsFixture):
+
+ def test_generate_reports(self):
+ report = self.cbr_hook._generate_perf_plugin_report()
+
+ self.assertEqual(len(report.keys()), 12)
+ self.assertEqual(len(report["data"]["results"]), 1)
+
+ self.assertDictEqual(report["data"]["results"][0]["context"], _BM_CONTEXT)
+
+ self.assertEqual(report["create_time"], "2999-12-31T23:59:59Z")
+ self.assertEqual(report["data"]["end"], "3000-01-01T00:00:00Z")
+
+
+class TestBenchmarkThreadsReport(CombineBenchmarkResultsFixture):
+
+ def test_thread_from_name(self):
+ thread = self.bm_threads_report._thread_from_name("BM_Name/arg name:100/threads:10")
+ self.assertEqual(thread, "10")
+
+ thread = self.bm_threads_report._thread_from_name("BM_Name/arg name:100/threads:10_mean")
+ self.assertEqual(thread, "10_mean")
+
+ def test_generate_perf_plugin_dict(self):
+ # Also test add_report() in the process.
+ self.bm_threads_report.add_report(_BM_REPORT)
+ self.bm_threads_report.add_report(_BM_MEDIAN_REPORT)
+ self.assertEqual(len(self.bm_threads_report.thread_benchmark_map.keys()), 2)
+
+ report = self.bm_threads_report.generate_perf_plugin_dict()
+
+ self.assertIn("10", report.keys())
+ self.assertIn("10_median", report.keys())
+
+ self.assertEqual(len(report["10"]["error_values"]), 1)
+ self.assertEqual(len(report["10"]["ops_per_sec_values"]), 1)
+ self.assertEqual(report["10"]["ops_per_sec"], -303.0)
+
+ self.assertEqual(len(report["10_median"]["error_values"]), 1)
+ self.assertEqual(len(report["10_median"]["ops_per_sec_values"]), 1)
+ self.assertEqual(report["10_median"]["ops_per_sec"], -300.0)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/buildscripts/tests/test_aws_ec2.py b/buildscripts/tests/test_aws_ec2.py
index 40f433392f2..be2e3ddef92 100755
--- a/buildscripts/tests/test_aws_ec2.py
+++ b/buildscripts/tests/test_aws_ec2.py
@@ -2,13 +2,11 @@
"""Unit test for buildscripts/aws_ec2.py."""
+from __future__ import absolute_import
+
import datetime
-import os
-import sys
import unittest
-if __name__ == "__main__" and __package__ is None:
- sys.path.append(os.getcwd())
from buildscripts import aws_ec2
_AMI = "ami-ed6bec86"
diff --git a/buildscripts/tests/test_fetch_test_lifecycle.py b/buildscripts/tests/test_fetch_test_lifecycle.py
index 471199b1d9a..8c581fd1b7c 100644
--- a/buildscripts/tests/test_fetch_test_lifecycle.py
+++ b/buildscripts/tests/test_fetch_test_lifecycle.py
@@ -1,4 +1,5 @@
"""Unit tests for the fetch_test_lifecycle.py script."""
+from __future__ import absolute_import
import unittest
diff --git a/buildscripts/tests/test_remote_operations.py b/buildscripts/tests/test_remote_operations.py
index 38f5e70c9d0..b468c45ebee 100755
--- a/buildscripts/tests/test_remote_operations.py
+++ b/buildscripts/tests/test_remote_operations.py
@@ -5,15 +5,14 @@
Note - Tests require sshd to be enabled on localhost with paswordless login
and can fail otherwise."""
+from __future__ import absolute_import
+
import os
import shutil
-import sys
import tempfile
import time
import unittest
-if __name__ == "__main__" and __package__ is None:
- sys.path.append(os.getcwd())
from buildscripts import remote_operations as rop