]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tests for the new while helper
authorAlfredo Deza <alfredo.deza@inktank.com>
Mon, 24 Feb 2014 21:21:58 +0000 (16:21 -0500)
committerAlfredo Deza <alfredo.deza@inktank.com>
Mon, 24 Feb 2014 21:21:58 +0000 (16:21 -0500)
Signed-off-by: Alfredo Deza <alfredo.deza@inktank.com>
teuthology/test/test_contextutil.py [new file with mode: 0644]

diff --git a/teuthology/test/test_contextutil.py b/teuthology/test/test_contextutil.py
new file mode 100644 (file)
index 0000000..656f1f5
--- /dev/null
@@ -0,0 +1,51 @@
+from pytest import raises
+from teuthology import contextutil
+
+
+class TestSafeWhile(object):
+
+    def setup(self):
+        self.fake_sleep = lambda s: True
+        self.s_while = contextutil.safe_while
+
+    def test_5_5_5_deal(self):
+        with raises(contextutil.MaxWhileTries):
+            with self.s_while(_sleeper=self.fake_sleep) as bomb:
+                while 1:
+                    bomb()
+
+    def test_5_5_1_deal(self):
+        with raises(contextutil.MaxWhileTries) as error:
+            with self.s_while(
+                tries=1,
+                _sleeper=self.fake_sleep
+            ) as bomb:
+                while 1:
+                    bomb()
+
+        msg = error.value[0]
+        assert 'waiting for 5 seconds' in msg
+
+    def test_1_5_5_deal(self):
+        with raises(contextutil.MaxWhileTries) as error:
+            with self.s_while(
+                sleep=1,
+                _sleeper=self.fake_sleep
+            ) as bomb:
+                while 1:
+                    bomb()
+
+        msg = error.value[0]
+        assert 'waiting for 55 seconds' in msg
+
+    def test_5_1_5_deal(self):
+        with raises(contextutil.MaxWhileTries) as error:
+            with self.s_while(
+                increment=1,
+                _sleeper=self.fake_sleep
+            ) as bomb:
+                while 1:
+                    bomb()
+
+        msg = error.value[0]
+        assert 'waiting for 35 seconds' in msg