Files
mongo/buildscripts/tests/resmokelib/testing/hooks/test_stepdown.py
Steve McClure b4b23946cd SERVER-90570: Enable formatting checks for buildscripts directory, excluding idl (#22254)
GitOrigin-RevId: 9d997a9f44cd43a8dec7c2a17fa2dbcd875e92f6
2024-05-16 22:07:36 +00:00

51 lines
1.8 KiB
Python

"""Unit tests for buildscripts/resmokelib/testing/hooks/stepdown.py."""
import logging
import os
import unittest
import mock
from buildscripts.resmokelib import errors
from buildscripts.resmokelib.testing.hooks import stepdown as _stepdown
from buildscripts.resmokelib.testing.hooks import lifecycle as lifecycle_interface
# pylint: disable=protected-access
class TestStepdownThread(unittest.TestCase):
@mock.patch("buildscripts.resmokelib.testing.fixtures.replicaset.ReplicaSetFixture")
@mock.patch("buildscripts.resmokelib.testing.fixtures.shardedcluster.ShardedClusterFixture")
@mock.patch(
"buildscripts.resmokelib.testing.hooks.stepdown._StepdownThread.is_alive",
mock.Mock(return_value=True),
)
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=lifecycle_interface.FlagBasedThreadLifecycle(),
background_reconfig=False,
fixture=shardcluster_fixture,
)
# 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()