Skip to content

Commit 9d04fdf

Browse files
committed
PYTHON-5356 - Init unified test clients for CSOT tests
1 parent 02c3df6 commit 9d04fdf

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

test/asynchronous/unified_format.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def _handle_placeholders(self, spec: dict, current: dict, path: str) -> Any:
257257
current[key] = self._handle_placeholders(spec, value, subpath)
258258
return current
259259

260-
async def _create_entity(self, entity_spec, uri=None):
260+
async def _create_entity(self, entity_spec, uri=None, init_client=False):
261261
if len(entity_spec) != 1:
262262
self.test.fail(f"Entity spec {entity_spec} did not contain exactly one top-level key")
263263

@@ -303,6 +303,8 @@ async def _create_entity(self, entity_spec, uri=None):
303303
if uri:
304304
kwargs["h"] = uri
305305
client = await self.test.async_rs_or_single_client(**kwargs)
306+
if init_client:
307+
await client.aconnect()
306308
self[spec["id"]] = client
307309
return
308310
elif entity_type == "database":
@@ -390,9 +392,9 @@ async def drop(self: AsyncGridFSBucket, *args: Any, **kwargs: Any) -> None:
390392

391393
self.test.fail(f"Unable to create entity of unknown type {entity_type}")
392394

393-
async def create_entities_from_spec(self, entity_spec, uri=None):
395+
async def create_entities_from_spec(self, entity_spec, uri=None, init_client=False):
394396
for spec in entity_spec:
395-
await self._create_entity(spec, uri=uri)
397+
await self._create_entity(spec, uri=uri, init_client=init_client)
396398

397399
def get_listener_for_client(self, client_name: str) -> EventListenerUtil:
398400
client = self[client_name]
@@ -1406,7 +1408,7 @@ async def run_scenario(self, spec, uri=None):
14061408
attempts = 3
14071409
for i in range(attempts):
14081410
try:
1409-
return await self._run_scenario(spec, uri)
1411+
return await self._run_scenario(spec, uri, init_client=True)
14101412
except (AssertionError, OperationFailure) as exc:
14111413
if isinstance(exc, OperationFailure) and (
14121414
_IS_SYNC or "failpoint" not in exc._message
@@ -1426,7 +1428,7 @@ async def run_scenario(self, spec, uri=None):
14261428
await self._run_scenario(spec, uri)
14271429
return None
14281430

1429-
async def _run_scenario(self, spec, uri=None):
1431+
async def _run_scenario(self, spec, uri=None, init_client=False):
14301432
# maybe skip test manually
14311433
self.maybe_skip_test(spec)
14321434

@@ -1444,7 +1446,7 @@ async def _run_scenario(self, spec, uri=None):
14441446
self._uri = uri
14451447
self.entity_map = EntityMapUtil(self)
14461448
await self.entity_map.create_entities_from_spec(
1447-
self.TEST_SPEC.get("createEntities", []), uri=uri
1449+
self.TEST_SPEC.get("createEntities", []), uri=uri, init_client=init_client
14481450
)
14491451
self._cluster_time = None
14501452
# process initialData

test/unified_format.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def _handle_placeholders(self, spec: dict, current: dict, path: str) -> Any:
256256
current[key] = self._handle_placeholders(spec, value, subpath)
257257
return current
258258

259-
def _create_entity(self, entity_spec, uri=None):
259+
def _create_entity(self, entity_spec, uri=None, init_client=False):
260260
if len(entity_spec) != 1:
261261
self.test.fail(f"Entity spec {entity_spec} did not contain exactly one top-level key")
262262

@@ -302,6 +302,8 @@ def _create_entity(self, entity_spec, uri=None):
302302
if uri:
303303
kwargs["h"] = uri
304304
client = self.test.rs_or_single_client(**kwargs)
305+
if init_client:
306+
client._connect()
305307
self[spec["id"]] = client
306308
return
307309
elif entity_type == "database":
@@ -389,9 +391,9 @@ def drop(self: GridFSBucket, *args: Any, **kwargs: Any) -> None:
389391

390392
self.test.fail(f"Unable to create entity of unknown type {entity_type}")
391393

392-
def create_entities_from_spec(self, entity_spec, uri=None):
394+
def create_entities_from_spec(self, entity_spec, uri=None, init_client=False):
393395
for spec in entity_spec:
394-
self._create_entity(spec, uri=uri)
396+
self._create_entity(spec, uri=uri, init_client=init_client)
395397

396398
def get_listener_for_client(self, client_name: str) -> EventListenerUtil:
397399
client = self[client_name]
@@ -1393,7 +1395,7 @@ def run_scenario(self, spec, uri=None):
13931395
attempts = 3
13941396
for i in range(attempts):
13951397
try:
1396-
return self._run_scenario(spec, uri)
1398+
return self._run_scenario(spec, uri, init_client=True)
13971399
except (AssertionError, OperationFailure) as exc:
13981400
if isinstance(exc, OperationFailure) and (
13991401
_IS_SYNC or "failpoint" not in exc._message
@@ -1413,7 +1415,7 @@ def run_scenario(self, spec, uri=None):
14131415
self._run_scenario(spec, uri)
14141416
return None
14151417

1416-
def _run_scenario(self, spec, uri=None):
1418+
def _run_scenario(self, spec, uri=None, init_client=False):
14171419
# maybe skip test manually
14181420
self.maybe_skip_test(spec)
14191421

@@ -1430,7 +1432,9 @@ def _run_scenario(self, spec, uri=None):
14301432
# process createEntities
14311433
self._uri = uri
14321434
self.entity_map = EntityMapUtil(self)
1433-
self.entity_map.create_entities_from_spec(self.TEST_SPEC.get("createEntities", []), uri=uri)
1435+
self.entity_map.create_entities_from_spec(
1436+
self.TEST_SPEC.get("createEntities", []), uri=uri, init_client=init_client
1437+
)
14341438
self._cluster_time = None
14351439
# process initialData
14361440
if "initialData" in self.TEST_SPEC:

0 commit comments

Comments
 (0)