From 30a2f3f91a04d69368a3591f28874a8da6948e36 Mon Sep 17 00:00:00 2001 From: Mark Beierl Date: Mon, 28 Nov 2016 16:17:05 -0500 Subject: Data Handling Refactoring Break out test db interaction into new module and make the push event driven instead of the sleep that was there before. Change-Id: I9485aba1405f6c3b4ee5000168fbc037efa87c81 JIRA: STORPERF-90 Signed-off-by: Mark Beierl --- tests/db_tests/job_db_test.py | 5 +- tests/utilities_tests/data_handler_test.py | 76 ++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 tests/utilities_tests/data_handler_test.py (limited to 'tests') diff --git a/tests/db_tests/job_db_test.py b/tests/db_tests/job_db_test.py index fe3d9f1..ccfb9cc 100644 --- a/tests/db_tests/job_db_test.py +++ b/tests/db_tests/job_db_test.py @@ -7,14 +7,15 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -from storperf.db.job_db import JobDB -from storperf.workloads.rr import rr import os import sqlite3 import unittest import mock +from storperf.db.job_db import JobDB +from storperf.workloads.rr import rr + class JobDBTest(unittest.TestCase): diff --git a/tests/utilities_tests/data_handler_test.py b/tests/utilities_tests/data_handler_test.py new file mode 100644 index 0000000..482b98e --- /dev/null +++ b/tests/utilities_tests/data_handler_test.py @@ -0,0 +1,76 @@ +############################################################################## +# Copyright (c) 2016 EMC and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import os +import unittest + +import mock + +from storperf.utilities.data_handler import DataHandler + + +class MockGraphiteDB(object): + + def __init__(self): + self.called = False + + def fetch_averages(self, job_id): + self.called = True + return None + + +class DataHandlerTest(unittest.TestCase): + + def setUp(self): + self.event_listeners = set() + self.data_handler = DataHandler() + self._terminated = False + self.args = None + self.start_time = 0 + self.end_time = 1 + self.metadata = {} + self.block_sizes = "1" + self.queue_depths = "1" + mock.job_id = "1" + self.job_db = mock + self.pushed = False + pass + + @property + def terminated(self): + return self._terminated + + def push_results_to_db(self, *args): + self.pushed = True + pass + + def test_not_terminated_report(self): + self.data_handler.data_event(self) + + @mock.patch.dict(os.environ, {'TEST_DB_URL': 'mock'}) + @mock.patch("storperf.db.test_results_db.push_results_to_db") + @mock.patch("storperf.utilities.data_handler.GraphiteDB") + def test_terminated_report(self, mock_graphite_db, mock_results_db): + self._terminated = True + mock_results_db.side_effect = self.push_results_to_db + mock_graphite_db.side_effect = MockGraphiteDB + + self.data_handler.data_event(self) + self.assertEqual(True, self.pushed) + + @mock.patch.dict(os.environ, {'TEST_DB_URL': 'mock'}) + @mock.patch("storperf.db.test_results_db.push_results_to_db") + @mock.patch("storperf.utilities.data_handler.GraphiteDB") + def test_non_terminated_report(self, mock_graphite_db, mock_results_db): + self._terminated = False + mock_results_db.side_effect = self.push_results_to_db + mock_graphite_db.side_effect = MockGraphiteDB + + self.data_handler.data_event(self) + self.assertEqual(False, self.pushed) -- cgit 1.2.3-korg