summaryrefslogtreecommitdiff
path: root/buildscripts/tests
diff options
context:
space:
mode:
authorYves Duhem <yves.duhem@mongodb.com>2018-02-02 19:12:18 -0500
committerYves Duhem <yves.duhem@mongodb.com>2018-03-02 12:14:51 -0500
commit6618ad302577418504e9a1b7849bfa7d400d4c53 (patch)
tree0c8da44aa6d640fec123d7a064afc75c86869af9 /buildscripts/tests
parentb2d8bd06318e1fddf4f1579084bbda4fb556c176 (diff)
downloadmongo-6618ad302577418504e9a1b7849bfa7d400d4c53.tar.gz
SERVER-33396 Update fixture teardown to throw ServerFailure
Diffstat (limited to 'buildscripts/tests')
-rw-r--r--buildscripts/tests/resmokelib/testing/fixtures/test_interface.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/buildscripts/tests/resmokelib/testing/fixtures/test_interface.py b/buildscripts/tests/resmokelib/testing/fixtures/test_interface.py
new file mode 100644
index 00000000000..f098259860e
--- /dev/null
+++ b/buildscripts/tests/resmokelib/testing/fixtures/test_interface.py
@@ -0,0 +1,55 @@
+"""Unit tests for the resmokelib.testing.fixtures.interface module."""
+import logging
+import unittest
+
+from buildscripts.resmokelib import errors
+from buildscripts.resmokelib.testing.fixtures import interface
+
+
+class TestFixture(unittest.TestCase):
+ def test_teardown_ok(self):
+ raising_fixture = UnitTestFixture(should_raise=False)
+ raising_fixture.teardown()
+
+ def test_teardown_raise(self):
+ raising_fixture = UnitTestFixture(should_raise=True)
+ with self.assertRaises(errors.ServerFailure):
+ raising_fixture.teardown()
+
+
+class TestFixtureTeardownHandler(unittest.TestCase):
+
+ def test_teardown_ok(self):
+ handler = interface.FixtureTeardownHandler(logging.getLogger("handler_unittests"))
+ # Before any teardown.
+ self.assertTrue(handler.was_successful())
+ self.assertIsNone(handler.get_error_message())
+ # Successful teardown.
+ ok_fixture = UnitTestFixture(should_raise=False)
+ handler.teardown(ok_fixture, "ok")
+ # After successful teardown.
+ self.assertTrue(handler.was_successful())
+ self.assertIsNone(handler.get_error_message())
+
+ def test_teardown_error(self):
+ handler = interface.FixtureTeardownHandler(logging.getLogger("handler_unittests"))
+ # Failing teardown.
+ ko_fixture = UnitTestFixture(should_raise=True)
+ handler.teardown(ko_fixture, "ko")
+ # After failed teardown.
+ self.assertFalse(handler.was_successful())
+ expected_msg = "Error while stopping ko: " + UnitTestFixture.ERROR_MESSAGE
+ self.assertEqual(expected_msg, handler.get_error_message())
+
+
+class UnitTestFixture(interface.Fixture):
+ ERROR_MESSAGE = "Failed"
+
+ def __init__(self, should_raise=False):
+ logger = logging.getLogger("fixture_unittests")
+ interface.Fixture.__init__(self, logger, 99)
+ self._should_raise = should_raise
+
+ def _do_teardown(self):
+ if self._should_raise:
+ raise errors.ServerFailure(self.ERROR_MESSAGE)