summaryrefslogtreecommitdiffstats
path: root/tests/utilities_tests
diff options
context:
space:
mode:
authorMark Beierl <mark.beierl@dell.com>2016-11-25 13:28:40 -0500
committerMark Beierl <mark.beierl@dell.com>2016-11-25 13:40:34 -0500
commit776ff48bc805fbca34811b54ebd7a3626a20f817 (patch)
treeda3c2a91453a4cd80614891a2e61d8511bb0c71a /tests/utilities_tests
parent227bb19115eaab4f689cb570f0a5574cd5e318bb (diff)
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 <mark.beierl@dell.com>
Diffstat (limited to 'tests/utilities_tests')
-rw-r--r--tests/utilities_tests/__init__.py3
-rw-r--r--tests/utilities_tests/thread_gate_test.py57
2 files changed, 60 insertions, 0 deletions
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