Beispiel #1
0
    def test_pause_throws_error(self, shardcluster_fixture, rs_fixture):
        stepdown_thread = _stepdown._StepdownThread(
            logger=logging.getLogger("hook_logger"),
            mongos_fixtures=[shardcluster_fixture.mongos],
            rs_fixtures=[rs_fixture],
            stepdown_interval_secs=8,
            terminate=False,
            kill=False,
            stepdown_lifecycle=_stepdown.FlagBasedStepdownLifecycle(),
            wait_for_mongos_retarget=False,
            stepdown_via_heartbeats=True,
            background_reconfig=False,
        )

        # doesn't throw error when fixtures are running
        stepdown_thread.pause()

        # throws error when replica set fixture is not running
        rs_fixture.is_running.return_value = False
        try:
            with self.assertRaises(errors.ServerFailure):
                stepdown_thread.pause()
        finally:
            rs_fixture.is_running.return_value = True

        # throws error when MongoS fixture is not running
        shardcluster_fixture.mongos.is_running.return_value = False
        with self.assertRaises(errors.ServerFailure):
            stepdown_thread.pause()
Beispiel #2
0
    def test_waiting_for_stepdown_permitted_is_interruptible(
            self, MockCondition):  # pylint: disable=invalid-name
        lifecycle = _stepdown.FlagBasedStepdownLifecycle()
        lifecycle.mark_test_started()
        lifecycle.mark_test_finished()

        def call_stop_while_waiting():
            lock = _get_threading_lock(self, MockCondition)
            lock.release()
            lifecycle.stop()
            lock.acquire()

        cond = MockCondition.return_value
        cond.wait.side_effect = call_stop_while_waiting

        self.assertFalse(lifecycle.wait_for_stepdown_permitted())
        self.assertTrue(cond.wait.called)
Beispiel #3
0
 def test_stepdown_permitted_after_test_starts(self):
     lifecycle = _stepdown.FlagBasedStepdownLifecycle()
     lifecycle.mark_test_started()
     self.assertTrue(lifecycle.wait_for_stepdown_permitted())
Beispiel #4
0
 def test_becomes_idle_after_test_finishes(self):
     lifecycle = _stepdown.FlagBasedStepdownLifecycle()
     lifecycle.mark_test_started()
     self.assertFalse(lifecycle.poll_for_idle_request())
     lifecycle.mark_test_finished()
     self.assertTrue(lifecycle.poll_for_idle_request())