Skip to content

Commit 7d5688e

Browse files
committed
Unified test runner setup fixes
1 parent 31d0752 commit 7d5688e

File tree

4 files changed

+34
-48
lines changed

4 files changed

+34
-48
lines changed

test/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,6 @@ def setUp(self) -> None:
11731173
super().setUp()
11741174

11751175
self.client_knobs = client_knobs(heartbeat_frequency=0.001, min_heartbeat_interval=0.001)
1176-
11771176
self.client_knobs.enable()
11781177

11791178
def tearDown(self) -> None:

test/asynchronous/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,6 @@ async def asyncSetUp(self) -> None:
11911191
await super().asyncSetUp()
11921192

11931193
self.client_knobs = client_knobs(heartbeat_frequency=0.001, min_heartbeat_interval=0.001)
1194-
11951194
self.client_knobs.enable()
11961195

11971196
async def asyncTearDown(self) -> None:

test/asynchronous/unified_format.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -478,55 +478,42 @@ async def insert_initial_data(self, initial_data):
478478
# Ensure collection exists
479479
await db.create_collection(coll_name, write_concern=wc, **opts)
480480

481-
@classmethod
482-
async def _setup_class(cls):
481+
async def asyncSetUp(self):
483482
# super call creates internal client cls.client
484-
await super()._setup_class()
483+
await super().asyncSetUp()
485484
# process file-level runOnRequirements
486-
run_on_spec = cls.TEST_SPEC.get("runOnRequirements", [])
487-
if not await cls.should_run_on(run_on_spec):
488-
raise unittest.SkipTest(f"{cls.__name__} runOnRequirements not satisfied")
485+
run_on_spec = self.TEST_SPEC.get("runOnRequirements", [])
486+
if not await self.should_run_on(run_on_spec):
487+
raise unittest.SkipTest(f"{self.__class__.__name__} runOnRequirements not satisfied")
489488

490489
# add any special-casing for skipping tests here
491490
if async_client_context.storage_engine == "mmapv1":
492-
if "retryable-writes" in cls.TEST_SPEC["description"] or "retryable_writes" in str(
493-
cls.TEST_PATH
491+
if "retryable-writes" in self.TEST_SPEC["description"] or "retryable_writes" in str(
492+
self.TEST_PATH
494493
):
495494
raise unittest.SkipTest("MMAPv1 does not support retryWrites=True")
496495

497496
# Handle mongos_clients for transactions tests.
498-
cls.mongos_clients = []
497+
self.mongos_clients = []
499498
if (
500499
async_client_context.supports_transactions()
501500
and not async_client_context.load_balancer
502501
and not async_client_context.serverless
503502
):
504503
for address in async_client_context.mongoses:
505-
cls.mongos_clients.append(
506-
await cls.unmanaged_async_single_client("{}:{}".format(*address))
507-
)
504+
self.mongos_clients.append(await self.async_single_client("{}:{}".format(*address)))
508505

509506
# Speed up the tests by decreasing the heartbeat frequency.
510-
cls.knobs = client_knobs(
507+
self.knobs = client_knobs(
511508
heartbeat_frequency=0.1,
512509
min_heartbeat_interval=0.1,
513510
kill_cursor_frequency=0.1,
514511
events_queue_frequency=0.1,
515512
)
516-
cls.knobs.enable()
517-
518-
@classmethod
519-
async def _tearDown_class(cls):
520-
cls.knobs.disable()
521-
for client in cls.mongos_clients:
522-
await client.close()
523-
await super()._tearDown_class()
513+
self.knobs.enable()
524514

525-
async def asyncSetUp(self):
526-
await super().asyncSetUp()
527515
# process schemaVersion
528516
# note: we check major schema version during class generation
529-
# note: we do this here because we cannot run assertions in setUpClass
530517
version = Version.from_string(self.TEST_SPEC["schemaVersion"])
531518
self.assertLessEqual(
532519
version,
@@ -537,6 +524,12 @@ async def asyncSetUp(self):
537524
# initialize internals
538525
self.match_evaluator = MatchEvaluatorUtil(self)
539526

527+
async def asyncTearDown(self):
528+
self.knobs.disable()
529+
for client in self.mongos_clients:
530+
await client.close()
531+
await super().asyncTearDown()
532+
540533
def maybe_skip_test(self, spec):
541534
# add any special-casing for skipping tests here
542535
if async_client_context.storage_engine == "mmapv1":

test/unified_format.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -477,53 +477,42 @@ def insert_initial_data(self, initial_data):
477477
# Ensure collection exists
478478
db.create_collection(coll_name, write_concern=wc, **opts)
479479

480-
@classmethod
481-
def _setup_class(cls):
480+
def setUp(self):
482481
# super call creates internal client cls.client
483-
super()._setup_class()
482+
super().setUp()
484483
# process file-level runOnRequirements
485-
run_on_spec = cls.TEST_SPEC.get("runOnRequirements", [])
486-
if not cls.should_run_on(run_on_spec):
487-
raise unittest.SkipTest(f"{cls.__name__} runOnRequirements not satisfied")
484+
run_on_spec = self.TEST_SPEC.get("runOnRequirements", [])
485+
if not self.should_run_on(run_on_spec):
486+
raise unittest.SkipTest(f"{self.__class__.__name__} runOnRequirements not satisfied")
488487

489488
# add any special-casing for skipping tests here
490489
if client_context.storage_engine == "mmapv1":
491-
if "retryable-writes" in cls.TEST_SPEC["description"] or "retryable_writes" in str(
492-
cls.TEST_PATH
490+
if "retryable-writes" in self.TEST_SPEC["description"] or "retryable_writes" in str(
491+
self.TEST_PATH
493492
):
494493
raise unittest.SkipTest("MMAPv1 does not support retryWrites=True")
495494

496495
# Handle mongos_clients for transactions tests.
497-
cls.mongos_clients = []
496+
self.mongos_clients = []
498497
if (
499498
client_context.supports_transactions()
500499
and not client_context.load_balancer
501500
and not client_context.serverless
502501
):
503502
for address in client_context.mongoses:
504-
cls.mongos_clients.append(cls.unmanaged_single_client("{}:{}".format(*address)))
503+
self.mongos_clients.append(self.single_client("{}:{}".format(*address)))
505504

506505
# Speed up the tests by decreasing the heartbeat frequency.
507-
cls.knobs = client_knobs(
506+
self.knobs = client_knobs(
508507
heartbeat_frequency=0.1,
509508
min_heartbeat_interval=0.1,
510509
kill_cursor_frequency=0.1,
511510
events_queue_frequency=0.1,
512511
)
513-
cls.knobs.enable()
512+
self.knobs.enable()
514513

515-
@classmethod
516-
def _tearDown_class(cls):
517-
cls.knobs.disable()
518-
for client in cls.mongos_clients:
519-
client.close()
520-
super()._tearDown_class()
521-
522-
def setUp(self):
523-
super().setUp()
524514
# process schemaVersion
525515
# note: we check major schema version during class generation
526-
# note: we do this here because we cannot run assertions in setUpClass
527516
version = Version.from_string(self.TEST_SPEC["schemaVersion"])
528517
self.assertLessEqual(
529518
version,
@@ -534,6 +523,12 @@ def setUp(self):
534523
# initialize internals
535524
self.match_evaluator = MatchEvaluatorUtil(self)
536525

526+
def tearDown(self):
527+
self.knobs.disable()
528+
for client in self.mongos_clients:
529+
client.close()
530+
super().tearDown()
531+
537532
def maybe_skip_test(self, spec):
538533
# add any special-casing for skipping tests here
539534
if client_context.storage_engine == "mmapv1":

0 commit comments

Comments
 (0)