summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2019-08-13 16:02:18 -0400
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2019-08-13 16:02:18 -0400
commitcd543c54468d7e0a601a35b0a7ecc39d98bf43a6 (patch)
tree94eba2767990e332f2cf136d877b876599102443
parenta20c374983724f59ae5e6700445070045aac7c84 (diff)
downloadmongo-cd543c54468d7e0a601a35b0a7ecc39d98bf43a6.tar.gz
SERVER-42622 Call teardown_fixture() even if setup_fixture() errors.
(cherry picked from commit 45b43da30b348b6eb471e9a5c5e4b33550fc53ff)
-rw-r--r--buildscripts/resmokelib/testing/job.py24
-rw-r--r--buildscripts/tests/resmokelib/testing/test_job.py5
2 files changed, 18 insertions, 11 deletions
diff --git a/buildscripts/resmokelib/testing/job.py b/buildscripts/resmokelib/testing/job.py
index 6219acc1f17..312318ab5ff 100644
--- a/buildscripts/resmokelib/testing/job.py
+++ b/buildscripts/resmokelib/testing/job.py
@@ -81,6 +81,7 @@ class Job(object): # pylint: disable=too-many-instance-attributes
will be run before this method returns. If an error occurs
while destroying the fixture, then the 'teardown_flag' will be set.
"""
+ setup_succeeded = True
if setup_flag is not None:
try:
setup_succeeded = self.setup_fixture()
@@ -98,19 +99,20 @@ class Job(object): # pylint: disable=too-many-instance-attributes
setup_succeeded = False
if not setup_succeeded:
+ setup_flag.set()
self._interrupt_all_jobs(queue, interrupt_flag)
- return
- try:
- self._run(queue, interrupt_flag)
- except errors.StopExecution as err:
- # Stop running tests immediately.
- self.logger.error("Received a StopExecution exception: %s.", err)
- self._interrupt_all_jobs(queue, interrupt_flag)
- except: # pylint: disable=bare-except
- # Unknown error, stop execution.
- self.logger.exception("Encountered an error during test execution.")
- self._interrupt_all_jobs(queue, interrupt_flag)
+ if setup_succeeded:
+ try:
+ self._run(queue, interrupt_flag)
+ except errors.StopExecution as err:
+ # Stop running tests immediately.
+ self.logger.error("Received a StopExecution exception: %s.", err)
+ self._interrupt_all_jobs(queue, interrupt_flag)
+ except: # pylint: disable=bare-except
+ # Unknown error, stop execution.
+ self.logger.exception("Encountered an error during test execution.")
+ self._interrupt_all_jobs(queue, interrupt_flag)
if teardown_flag is not None:
try:
diff --git a/buildscripts/tests/resmokelib/testing/test_job.py b/buildscripts/tests/resmokelib/testing/test_job.py
index cac4930475e..36ad005c997 100644
--- a/buildscripts/tests/resmokelib/testing/test_job.py
+++ b/buildscripts/tests/resmokelib/testing/test_job.py
@@ -233,8 +233,13 @@ class TestFixtureSetupAndTeardown(unittest.TestCase):
self.__job_object(queue, interrupt_flag, setup_flag, teardown_flag)
self.assertEqual(setup_succeeded, not interrupt_flag.is_set())
+ self.assertEqual(setup_succeeded, not setup_flag.is_set())
self.assertEqual(teardown_succeeded, not teardown_flag.is_set())
+ # teardown_fixture() should be called even if setup_fixture() raises an exception.
+ self.__job_object.setup_fixture.assert_called()
+ self.__job_object.teardown_fixture.assert_called()
+
def test_setup_and_teardown_both_succeed(self):
self.__assert_when_run_tests()