From 776ff48bc805fbca34811b54ebd7a3626a20f817 Mon Sep 17 00:00:00 2001 From: Mark Beierl Date: Fri, 25 Nov 2016 13:28:40 -0500 Subject: Data Reporting Gate Module that allows passing of a gate only once all other peers have also reported in within a specified time period Change-Id: If4baf1d4377026c7833a6f30bfc2e36698f675e8 JIRA: STORPERF-71 Signed-off-by: Mark Beierl --- tests/utilities_tests/__init__.py | 3 ++ tests/utilities_tests/thread_gate_test.py | 57 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/utilities_tests/thread_gate_test.py (limited to 'tests') diff --git a/tests/utilities_tests/__init__.py b/tests/utilities_tests/__init__.py index 73444b6..6218fe3 100644 --- a/tests/utilities_tests/__init__.py +++ b/tests/utilities_tests/__init__.py @@ -6,3 +6,6 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import logging + +logging.basicConfig(level=logging.DEBUG) diff --git a/tests/utilities_tests/thread_gate_test.py b/tests/utilities_tests/thread_gate_test.py new file mode 100644 index 0000000..de8b15a --- /dev/null +++ b/tests/utilities_tests/thread_gate_test.py @@ -0,0 +1,57 @@ +############################################################################## +# 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 time +import unittest + +from storperf.utilities.thread_gate import FailureToReportException +from storperf.utilities.thread_gate import ThreadGate + + +class ThreadGateTest(unittest.TestCase): + + def setUp(self): + pass + + def test_one_one_report(self): + gate = ThreadGate(1) + self.assertEqual(True, gate.report(1)) + + def test_two_one_report(self): + gate = ThreadGate(2) + self.assertEqual(False, gate.report(1)) + + def test_two_two_reports(self): + gate = ThreadGate(2) + self.assertEqual(False, gate.report(1)) + self.assertEqual(True, gate.report(2)) + + def test_two_one_duplicate_reports(self): + gate = ThreadGate(2) + self.assertEqual(False, gate.report(1)) + self.assertEqual(False, gate.report(1)) + self.assertEqual(True, gate.report(2)) + + def test_two_old_old_report(self): + timeout = 5 + gate = ThreadGate(2, timeout) + report_time = time.time() - (timeout * 2) + gate._registrants[2] = report_time + self.assertEqual(False, gate.report(1)) + + def test_two_never_report(self): + timeout = 5 + gate = ThreadGate(2, timeout) + report_time = time.time() - (timeout * 3) + gate._creation_time = report_time + try: + gate.report(1) + self.fail() + except FailureToReportException: + pass -- cgit 1.2.3-korg