From 9ac70d7c36dabb86e5b1df3b462f1cbfdb83cff7 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Tue, 29 Mar 2022 13:27:37 -0700 Subject: [PATCH 1/2] PYTHON-3160 Fix mmapv1 tests --- test/change_streams/unified/change-streams.json | 4 +--- .../sessions/driver-sessions-dirty-session-errors.json | 1 - test/test_session.py | 10 ++++------ test/unified_format.py | 5 ++++- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/test/change_streams/unified/change-streams.json b/test/change_streams/unified/change-streams.json index 5fd2544ce0..20cce513ee 100644 --- a/test/change_streams/unified/change-streams.json +++ b/test/change_streams/unified/change-streams.json @@ -181,9 +181,7 @@ "name": "test1" } }, - "expectError": { - "isClientError": false - } + "saveResultAsEntity": "changeStream0" } ], "expectEvents": [ diff --git a/test/sessions/driver-sessions-dirty-session-errors.json b/test/sessions/driver-sessions-dirty-session-errors.json index 88a9171db1..361ea83d7b 100644 --- a/test/sessions/driver-sessions-dirty-session-errors.json +++ b/test/sessions/driver-sessions-dirty-session-errors.json @@ -448,7 +448,6 @@ "name": "insertOne", "object": "collection0", "arguments": { - "session": "session0", "document": { "_id": 2 } diff --git a/test/test_session.py b/test/test_session.py index 53609c70cb..e6f15de6bf 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -183,12 +183,11 @@ def test_implicit_sessions_checkout(self): # "To confirm that implicit sessions only allocate their server session after a # successful connection checkout" test from Driver Sessions Spec. succeeded = False + lsid_set = set() failures = 0 for _ in range(5): listener = EventListener() - client = rs_or_single_client( - event_listeners=[listener], maxPoolSize=1, retryWrites=True - ) + client = rs_or_single_client(event_listeners=[listener], maxPoolSize=1) cursor = client.db.test.find({}) ops: List[Tuple[Callable, List[Any]]] = [ (client.db.test.find_one, [{"_id": 1}]), @@ -225,7 +224,7 @@ def thread_target(op, *args): thread.join() self.assertIsNone(thread.exc) client.close() - lsid_set = set() + lsid_set.clear() for i in listener.results["started"]: if i.command.get("lsid"): lsid_set.add(i.command.get("lsid")["id"]) @@ -233,8 +232,7 @@ def thread_target(op, *args): succeeded = True else: failures += 1 - print(failures) - self.assertTrue(succeeded) + self.assertTrue(succeeded, lsid_set) def test_pool_lifo(self): # "Pool is LIFO" test from Driver Sessions Spec. diff --git a/test/unified_format.py b/test/unified_format.py index 5bf98c5451..218800bf1c 100644 --- a/test/unified_format.py +++ b/test/unified_format.py @@ -766,7 +766,10 @@ def setUp(self): def maybe_skip_test(self, spec): # add any special-casing for skipping tests here if client_context.storage_engine == "mmapv1": - if "Dirty explicit session is discarded" in spec["description"]: + if ( + "Dirty explicit session is discarded" in spec["description"] + or "Dirty implicit session is discarded" in spec["description"] + ): raise unittest.SkipTest("MMAPv1 does not support retryWrites=True") elif "Client side error in command starting transaction" in spec["description"]: raise unittest.SkipTest("Implement PYTHON-1894") From ed6d23584100222b2628b0ace343e53d0bf1168b Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Wed, 30 Mar 2022 16:45:48 -0700 Subject: [PATCH 2/2] PYTHON-3160 Fix, skip change stream tests on mmapv1 --- test/change_streams/unified/change-streams.json | 4 +++- test/unified_format.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/test/change_streams/unified/change-streams.json b/test/change_streams/unified/change-streams.json index 20cce513ee..5fd2544ce0 100644 --- a/test/change_streams/unified/change-streams.json +++ b/test/change_streams/unified/change-streams.json @@ -181,7 +181,9 @@ "name": "test1" } }, - "saveResultAsEntity": "changeStream0" + "expectError": { + "isClientError": false + } } ], "expectEvents": [ diff --git a/test/unified_format.py b/test/unified_format.py index 218800bf1c..adfd0cac0a 100644 --- a/test/unified_format.py +++ b/test/unified_format.py @@ -774,6 +774,22 @@ def maybe_skip_test(self, spec): elif "Client side error in command starting transaction" in spec["description"]: raise unittest.SkipTest("Implement PYTHON-1894") + # Some tests need to be skipped based on the operations they try to run. + for op in spec["operations"]: + name = op["name"] + if name == "count": + self.skipTest("PyMongo does not support count()") + if name == "listIndexNames": + self.skipTest("PyMongo does not support list_index_names()") + if client_context.storage_engine == "mmapv1": + if name == "createChangeStream": + self.skipTest("MMAPv1 does not support change streams") + if name == "withTransaction" or name == "startTransaction": + self.skipTest("MMAPv1 does not support document-level locking") + if not client_context.test_commands_enabled: + if name == "failPoint" or name == "targetedFailPoint": + self.skipTest("Test commands must be enabled to use fail points") + def process_error(self, exception, spec): is_error = spec.get("isError") is_client_error = spec.get("isClientError")