Files
mongo/buildscripts/resmokelib/testing/testcases/fixture.py
Matthew Russotto 8d12269eec SERVER-109844 Basic support for disaggregated storage clusters (#40566)
Co-authored-by: Benety Goh <benety@mongodb.com>
Co-authored-by: Mathias Stearn <mathias@mongodb.com>
Co-authored-by: Kaitlin Mahar <kaitlin.mahar@mongodb.com>
Co-authored-by: Brandon Stoll <bstoll@users.noreply.github.com>
Co-authored-by: Vanessa Noia <54818020+nessnoia@users.noreply.github.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: Vishnu K <vishnu.kaushik@mongodb.com>
Co-authored-by: Sunil Narasimhamurthy <suniltheta@gmail.com>
Co-authored-by: Jiawei Yang <youngyang0820@gmail.com>
Co-authored-by: Will Korteland <korteland@users.noreply.github.com>
Co-authored-by: Saman Memaripour <amirsaman.memaripour@mongodb.com>
Co-authored-by: huayu-ouyang <huayu.ouyang@mongodb.com>
Co-authored-by: Suganthi Mani <38441312+smani87@users.noreply.github.com>
Co-authored-by: Thomas Goyne <thomas.goyne@mongodb.com>
Co-authored-by: Haley Connelly <haley.connelly@mongodb.com>
Co-authored-by: Billy Donahue <BillyDonahue@users.noreply.github.com>
Co-authored-by: Kirollos Morkos <kiro.morkos@mongodb.com>
Co-authored-by: Lingzhi Deng <lingzhi.deng@mongodb.com>
Co-authored-by: Hartek Sabharwal <hartek.sabharwal@mongodb.com>
Co-authored-by: Aaron Himelman <aaron.himelman@mongodb.com>
Co-authored-by: Moustafa Maher <m.maher@mongodb.com>
Co-authored-by: prathmesh-kallurkar <prathmesh.kallurkar@mongodb.com>
Co-authored-by: Dan Larkin-York <13419935+dhly-etc@users.noreply.github.com>
Co-authored-by: Shreyas Kalyan <35750327+shreyaskalyan@users.noreply.github.com>
Co-authored-by: Shreyas Kalyan <shreyas.kalyan@mongodb.com>
Co-authored-by: Jonathan Reams <jbreams@mongodb.com>
Co-authored-by: adriangzz <adriangonzalezmontemayor@gmail.com>
Co-authored-by: Eric Milkie <milkie@users.noreply.github.com>
Co-authored-by: Aaron B <aaron.balsara@mongodb.com>
Co-authored-by: Ali Mir <ali.mir@mongodb.com>
Co-authored-by: Alex Blekhman <alexander.blekhman@mongodb.com>
Co-authored-by: mpobrien <mpobrien005@gmail.com>
Co-authored-by: Mark Benvenuto <mark.benvenuto@mongodb.com>
Co-authored-by: Ruby Chen <ruby.chen@mongodb.com>
Co-authored-by: Jagadish Nallapaneni <146780625+jagadishmdb@users.noreply.github.com>
Co-authored-by: Jonas Bergler <jonas.bergler@mongodb.com>
Co-authored-by: Peter Macko <peter.macko@mongodb.com>
Co-authored-by: Nic <nic.hollingum@mongodb.com>
Co-authored-by: Jiawei Yang <jiawei.yang@mongodb.com>
Co-authored-by: Jordi Serra Torrens <jordist@users.noreply.github.com>
Co-authored-by: Sunil Narasimhamurthy <sunil.narasimhamurthy@mongodb.com>
GitOrigin-RevId: a1c6609c820052137e2aa759711e86c337ae6f9f
2025-08-29 22:00:57 +00:00

136 lines
5.7 KiB
Python

"""The unittest.TestCase instances for setting up and tearing down fixtures."""
from pymongo import ReadPreference
from buildscripts.resmokelib import errors
from buildscripts.resmokelib.testing.fixtures import interface as fixture_interface
from buildscripts.resmokelib.testing.fixtures.external import ExternalFixture
from buildscripts.resmokelib.testing.fixtures.replicaset import ReplicaSetFixture
from buildscripts.resmokelib.testing.testcases import interface
from buildscripts.resmokelib.utils import registry
from buildscripts.resmokelib.utils.sharded_cluster_util import (
refresh_logical_session_cache_with_retry,
)
class FixtureTestCase(interface.TestCase):
"""Base class for the fixture test cases."""
REGISTERED_NAME = registry.LEAVE_UNREGISTERED
def __init__(self, logger, job_name, phase):
"""Initialize the FixtureTestCase."""
interface.TestCase.__init__(
self, logger, "Fixture test", "{}_fixture_{}".format(job_name, phase), dynamic=True
)
self.job_name = job_name
class FixtureSetupTestCase(FixtureTestCase):
"""TestCase for setting up a fixture."""
REGISTERED_NAME = registry.LEAVE_UNREGISTERED
PHASE = "setup"
def __init__(self, logger, fixture, job_name, times_set_up):
"""Initialize the FixtureSetupTestCase."""
specific_phase = "{phase}_{times_set_up}".format(
phase=self.PHASE, times_set_up=times_set_up
)
FixtureTestCase.__init__(self, logger, job_name, specific_phase)
self.fixture = fixture
def run_test(self):
"""Set up the fixture and wait for it to be ready."""
try:
self.return_code = 2
self.logger.info("Starting the setup of %s.", self.fixture)
self.fixture.setup()
self.logger.info("Waiting for %s to be ready.", self.fixture)
self.fixture.await_ready()
if (
not isinstance(self.fixture, (fixture_interface.NoOpFixture, ExternalFixture))
# TODO(SERVER-109851): Remove this.
# disagg mongod does not yet support "refreshLogicalSessionCacheNow" because it requires
# wtimeout support.
and self.fixture.__class__.__name__ != "DisaggFixture"
# Replica set with --configsvr cannot run refresh unless it is part of a sharded cluster.
and not (
isinstance(self.fixture, ReplicaSetFixture)
and "configsvr" in self.fixture.mongod_options
)
):
mongo_client = self.fixture.mongo_client(ReadPreference.PRIMARY)
# Read from the CSRS primary to gossip the most recent configTime to the mongos.
# This ensures that the latest state of the sessions collection can be seen
# by the router, when performing the LogicalSessionCache refresh.
mongo_client.admin["system.version"].find({})
# Perform the LogicalSessionCache refresh.
refresh_logical_session_cache_with_retry(mongo_client)
self.logger.info("Finished the setup of %s.", self.fixture)
self.return_code = 0
except errors.ServerFailure as err:
self.logger.error("An error occurred during the setup of %s: %s", self.fixture, err)
raise
except:
self.logger.exception("An error occurred during the setup of %s.", self.fixture)
raise
class FixtureTeardownTestCase(FixtureTestCase):
"""TestCase for tearing down a fixture."""
REGISTERED_NAME = registry.LEAVE_UNREGISTERED
PHASE = "teardown"
def __init__(self, logger, fixture, job_name):
"""Initialize the FixtureTeardownTestCase."""
FixtureTestCase.__init__(self, logger, job_name, self.PHASE)
self.fixture = fixture
def run_test(self):
"""Tear down the fixture."""
try:
self.return_code = 2
self.logger.info("Starting the teardown of %s.", self.fixture)
self.fixture.teardown(finished=True)
self.logger.info("Finished the teardown of %s.", self.fixture)
self.return_code = 0
except errors.ServerFailure as err:
self.logger.error("An error occurred during the teardown of %s: %s", self.fixture, err)
raise
except:
self.logger.exception("An error occurred during the teardown of %s.", self.fixture)
raise
class FixtureAbortTestCase(FixtureTestCase):
"""TestCase for killing a fixture. Intended for use before archiving a failed test."""
REGISTERED_NAME = registry.LEAVE_UNREGISTERED
PHASE = "abort"
def __init__(self, logger, fixture, job_name, times_set_up):
"""Initialize the FixtureAbortTestCase."""
specific_phase = "{phase}_{times_set_up}".format(
phase=self.PHASE, times_set_up=times_set_up
)
FixtureTestCase.__init__(self, logger, job_name, specific_phase)
self.fixture = fixture
def run_test(self):
"""Tear down the fixture."""
try:
self.return_code = 2 # Test return code of 2 is used for fixture failures.
self.logger.info("Aborting the fixture %s due to test failure.", self.fixture)
self.fixture.teardown(finished=False, mode=fixture_interface.TeardownMode.ABORT)
self.logger.info("Finished aborting %s.", self.fixture)
self.return_code = 0
except errors.ServerFailure:
# If the server wasn't already running, we can't exactly fail to abort it.
self.logger.info("Finished aborting %s.", self.fixture)
self.return_code = 0
except:
self.logger.exception("An error occurred while aborting %s.", self.fixture)
raise