summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '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