Files
mongo/buildscripts/tests/resmokelib/testing/hooks/test_stepdown.py
Juan Gu 7209d62b77 SERVER-99522 Delete dead py linters (#31760)
GitOrigin-RevId: 3aedfa559dda734d4d89fefe0fe1154a5a3cf04d
2025-04-09 19:33:45 +00:00

49 lines
1.8 KiB
Python

"""Unit tests for buildscripts/resmokelib/testing/hooks/stepdown.py."""
import logging
import unittest
import mock
from buildscripts.resmokelib import errors
from buildscripts.resmokelib.testing.hooks import lifecycle as lifecycle_interface
from buildscripts.resmokelib.testing.hooks import stepdown as _stepdown
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,
randomize_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()