Skip to content

Commit e8900ad

Browse files
PYTHON-4227 Unified tests: Advance cluster_time of ClientSessions after initialData creation (#1603)
1 parent 79fb19c commit e8900ad

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

test/unified_format.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ def __init__(self, test_class):
432432
self._listeners: Dict[str, EventListenerUtil] = {}
433433
self._session_lsids: Dict[str, Mapping[str, Any]] = {}
434434
self.test: UnifiedSpecTestMixinV1 = test_class
435+
self._cluster_time: Mapping[str, Any] = {}
435436

436437
def __contains__(self, item):
437438
return item in self._entities
@@ -624,6 +625,14 @@ def get_lsid_for_session(self, session_name):
624625
# session has been closed.
625626
return self._session_lsids[session_name]
626627

628+
def advance_cluster_times(self) -> None:
629+
"""Manually synchronize entities when desired"""
630+
if not self._cluster_time:
631+
self._cluster_time = self.test.client.admin.command("ping").get("$clusterTime")
632+
for entity in self._entities.values():
633+
if isinstance(entity, ClientSession) and self._cluster_time:
634+
entity.advance_cluster_time(self._cluster_time)
635+
627636

628637
binary_types = (Binary, bytes)
629638
long_types = (Int64,)
@@ -1050,14 +1059,6 @@ def maybe_skip_test(self, spec):
10501059
self.skipTest("Implement PYTHON-1894")
10511060
if "timeoutMS applied to entire download" in spec["description"]:
10521061
self.skipTest("PyMongo's open_download_stream does not cap the stream's lifetime")
1053-
1054-
if "unpin after TransientTransactionError error on" in spec["description"]:
1055-
self.skipTest("Skipping TransientTransactionError pending PYTHON-4227")
1056-
if "withTransaction commits after callback returns" in spec["description"]:
1057-
self.skipTest("Skipping TransientTransactionError pending PYTHON-4303")
1058-
if "unpin on successful abort" in spec["description"]:
1059-
self.skipTest("Skipping TransientTransactionError pending PYTHON-4227")
1060-
10611062
if "unpin after non-transient error on abort" in spec["description"]:
10621063
if client_context.version[0] == 8:
10631064
self.skipTest("Skipping TransientTransactionError pending PYTHON-4182")
@@ -1519,6 +1520,7 @@ def _testOperation_targetedFailPoint(self, spec):
15191520

15201521
def _testOperation_createEntities(self, spec):
15211522
self.entity_map.create_entities_from_spec(spec["entities"], uri=self._uri)
1523+
self.entity_map.advance_cluster_times()
15221524

15231525
def _testOperation_assertSessionTransactionState(self, spec):
15241526
session = self.entity_map[spec["session"]]
@@ -1880,7 +1882,10 @@ def _run_scenario(self, spec, uri=None):
18801882
self.entity_map = EntityMapUtil(self)
18811883
self.entity_map.create_entities_from_spec(self.TEST_SPEC.get("createEntities", []), uri=uri)
18821884
# process initialData
1883-
self.insert_initial_data(self.TEST_SPEC.get("initialData", []))
1885+
if "initialData" in self.TEST_SPEC:
1886+
self.insert_initial_data(self.TEST_SPEC["initialData"])
1887+
self._cluster_time = self.client.admin.command("ping").get("$clusterTime")
1888+
self.entity_map.advance_cluster_times()
18841889

18851890
if "expectLogMessages" in spec:
18861891
expect_log_messages = spec["expectLogMessages"]

0 commit comments

Comments
 (0)