From 8b6bb832ac50ef50ed864e7b45223532fae88e36 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Fri, 14 Jun 2024 09:25:34 -0700 Subject: [PATCH] PYTHON-4503 - Re-enable accidentally disabled tests (#1683) --- test/test_client.py | 53 ++++++++++-------------------- test/test_fork.py | 1 - test/test_gridfs.py | 14 ++++---- test/test_mongos_load_balancing.py | 1 - test/test_read_preferences.py | 6 ---- test/test_session.py | 5 ++- 6 files changed, 26 insertions(+), 54 deletions(-) diff --git a/test/test_client.py b/test/test_client.py index af71c4890e..1cf01014b1 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -30,7 +30,6 @@ import sys import threading import time -import warnings from typing import Iterable, Type, no_type_check from unittest import mock from unittest.mock import patch @@ -617,7 +616,7 @@ def test_max_idle_time_reaper_default(self): with client_knobs(kill_cursor_frequency=0.1): # Assert reaper doesn't remove connections when maxIdleTimeMS not set client = rs_or_single_client() - server = client._get_topology()._select_server(readable_server_selector, _Op.TEST) + server = client._get_topology().select_server(readable_server_selector, _Op.TEST) with server._pool.checkout() as conn: pass self.assertEqual(1, len(server._pool.conns)) @@ -628,7 +627,7 @@ def test_max_idle_time_reaper_removes_stale_minPoolSize(self): with client_knobs(kill_cursor_frequency=0.1): # Assert reaper removes idle socket and replaces it with a new one client = rs_or_single_client(maxIdleTimeMS=500, minPoolSize=1) - server = client._get_topology()._select_server(readable_server_selector, _Op.TEST) + server = client._get_topology().select_server(readable_server_selector, _Op.TEST) with server._pool.checkout() as conn: pass # When the reaper runs at the same time as the get_socket, two @@ -642,7 +641,7 @@ def test_max_idle_time_reaper_does_not_exceed_maxPoolSize(self): with client_knobs(kill_cursor_frequency=0.1): # Assert reaper respects maxPoolSize when adding new connections. client = rs_or_single_client(maxIdleTimeMS=500, minPoolSize=1, maxPoolSize=1) - server = client._get_topology()._select_server(readable_server_selector, _Op.TEST) + server = client._get_topology().select_server(readable_server_selector, _Op.TEST) with server._pool.checkout() as conn: pass # When the reaper runs at the same time as the get_socket, @@ -656,7 +655,7 @@ def test_max_idle_time_reaper_removes_stale(self): with client_knobs(kill_cursor_frequency=0.1): # Assert reaper has removed idle socket and NOT replaced it client = rs_or_single_client(maxIdleTimeMS=500) - server = client._get_topology()._select_server(readable_server_selector, _Op.TEST) + server = client._get_topology().select_server(readable_server_selector, _Op.TEST) with server._pool.checkout() as conn_one: pass # Assert that the pool does not close connections prematurely. @@ -673,12 +672,12 @@ def test_max_idle_time_reaper_removes_stale(self): def test_min_pool_size(self): with client_knobs(kill_cursor_frequency=0.1): client = rs_or_single_client() - server = client._get_topology()._select_server(readable_server_selector, _Op.TEST) + server = client._get_topology().select_server(readable_server_selector, _Op.TEST) self.assertEqual(0, len(server._pool.conns)) # Assert that pool started up at minPoolSize client = rs_or_single_client(minPoolSize=10) - server = client._get_topology()._select_server(readable_server_selector, _Op.TEST) + server = client._get_topology().select_server(readable_server_selector, _Op.TEST) wait_until( lambda: len(server._pool.conns) == 10, "pool initialized with 10 connections", @@ -697,7 +696,7 @@ def test_max_idle_time_checkout(self): # Use high frequency to test _get_socket_no_auth. with client_knobs(kill_cursor_frequency=99999999): client = rs_or_single_client(maxIdleTimeMS=500) - server = client._get_topology()._select_server(readable_server_selector, _Op.TEST) + server = client._get_topology().select_server(readable_server_selector, _Op.TEST) with server._pool.checkout() as conn: pass self.assertEqual(1, len(server._pool.conns)) @@ -711,7 +710,7 @@ def test_max_idle_time_checkout(self): # Test that connections are reused if maxIdleTimeMS is not set. client = rs_or_single_client() - server = client._get_topology()._select_server(readable_server_selector, _Op.TEST) + server = client._get_topology().select_server(readable_server_selector, _Op.TEST) with server._pool.checkout() as conn: pass self.assertEqual(1, len(server._pool.conns)) @@ -1180,9 +1179,7 @@ def test_server_selection_timeout(self): client = MongoClient(serverSelectionTimeoutMS=100, connect=False) self.assertAlmostEqual(0.1, client.options.server_selection_timeout) - with warnings.catch_warnings(): - warnings.simplefilter("ignore", UserWarning) - client = MongoClient(serverSelectionTimeoutMS=0, connect=False) + client = MongoClient(serverSelectionTimeoutMS=0, connect=False) self.assertAlmostEqual(0, client.options.server_selection_timeout) @@ -1195,20 +1192,14 @@ def test_server_selection_timeout(self): client = MongoClient("mongodb://localhost/?serverSelectionTimeoutMS=100", connect=False) self.assertAlmostEqual(0.1, client.options.server_selection_timeout) - with warnings.catch_warnings(): - warnings.simplefilter("ignore", UserWarning) - client = MongoClient("mongodb://localhost/?serverSelectionTimeoutMS=0", connect=False) + client = MongoClient("mongodb://localhost/?serverSelectionTimeoutMS=0", connect=False) self.assertAlmostEqual(0, client.options.server_selection_timeout) # Test invalid timeout in URI ignored and set to default. - with warnings.catch_warnings(): - warnings.simplefilter("ignore", UserWarning) - client = MongoClient("mongodb://localhost/?serverSelectionTimeoutMS=-1", connect=False) + client = MongoClient("mongodb://localhost/?serverSelectionTimeoutMS=-1", connect=False) self.assertAlmostEqual(30, client.options.server_selection_timeout) - with warnings.catch_warnings(): - warnings.simplefilter("ignore", UserWarning) - client = MongoClient("mongodb://localhost/?serverSelectionTimeoutMS=", connect=False) + client = MongoClient("mongodb://localhost/?serverSelectionTimeoutMS=", connect=False) self.assertAlmostEqual(30, client.options.server_selection_timeout) def test_waitQueueTimeoutMS(self): @@ -1550,16 +1541,12 @@ def compression_settings(client): self.assertEqual(opts.compressors, []) self.assertEqual(opts.zlib_compression_level, -1) uri = "mongodb://localhost:27017/?compressors=foobar" - with warnings.catch_warnings(): - warnings.simplefilter("ignore", UserWarning) - client = MongoClient(uri, connect=False) + client = MongoClient(uri, connect=False) opts = compression_settings(client) self.assertEqual(opts.compressors, []) self.assertEqual(opts.zlib_compression_level, -1) uri = "mongodb://localhost:27017/?compressors=foobar,zlib" - with warnings.catch_warnings(): - warnings.simplefilter("ignore", UserWarning) - client = MongoClient(uri, connect=False) + client = MongoClient(uri, connect=False) opts = compression_settings(client) self.assertEqual(opts.compressors, ["zlib"]) self.assertEqual(opts.zlib_compression_level, -1) @@ -1567,16 +1554,12 @@ def compression_settings(client): # According to the connection string spec, unsupported values # just raise a warning and are ignored. uri = "mongodb://localhost:27017/?compressors=zlib&zlibCompressionLevel=10" - with warnings.catch_warnings(): - warnings.simplefilter("ignore", UserWarning) - client = MongoClient(uri, connect=False) + client = MongoClient(uri, connect=False) opts = compression_settings(client) self.assertEqual(opts.compressors, ["zlib"]) self.assertEqual(opts.zlib_compression_level, -1) uri = "mongodb://localhost:27017/?compressors=zlib&zlibCompressionLevel=-2" - with warnings.catch_warnings(): - warnings.simplefilter("ignore", UserWarning) - client = MongoClient(uri, connect=False) + client = MongoClient(uri, connect=False) opts = compression_settings(client) self.assertEqual(opts.compressors, ["zlib"]) self.assertEqual(opts.zlib_compression_level, -1) @@ -1598,9 +1581,7 @@ def compression_settings(client): if not _have_zstd(): uri = "mongodb://localhost:27017/?compressors=zstd" - with warnings.catch_warnings(): - warnings.simplefilter("ignore", UserWarning) - client = MongoClient(uri, connect=False) + client = MongoClient(uri, connect=False) opts = compression_settings(client) self.assertEqual(opts.compressors, []) else: diff --git a/test/test_fork.py b/test/test_fork.py index 8fc1cdbb55..1a89159435 100644 --- a/test/test_fork.py +++ b/test/test_fork.py @@ -65,7 +65,6 @@ def target(): with self.fork(target): pass - @unittest.skip("testing") def test_topology_reset(self): # Tests that topologies are different from each other. # Cannot use ID because virtual memory addresses may be the same. diff --git a/test/test_gridfs.py b/test/test_gridfs.py index 1ef17afc2b..f15f108040 100644 --- a/test/test_gridfs.py +++ b/test/test_gridfs.py @@ -443,13 +443,13 @@ def test_gridfs_find(self): cursor.close() self.assertRaises(TypeError, self.fs.find, {}, {"_id": True}) - # def test_delete_not_initialized(self): - # # Creating a cursor with invalid arguments will not run __init__ - # # but will still call __del__. - # cursor = GridOutCursor.__new__(GridOutCursor) # Skip calling __init__ - # with self.assertRaises(TypeError): - # cursor.__init__(self.db.fs.files, {}, {"_id": True}) # type: ignore - # cursor.__del__() # no error + def test_delete_not_initialized(self): + # Creating a cursor with invalid arguments will not run __init__ + # but will still call __del__. + cursor = GridOutCursor.__new__(GridOutCursor) # Skip calling __init__ + with self.assertRaises(TypeError): + cursor.__init__(self.db.fs.files, {}, {"_id": True}) # type: ignore + cursor.__del__() # no error def test_gridfs_find_one(self): self.assertEqual(None, self.fs.find_one()) diff --git a/test/test_mongos_load_balancing.py b/test/test_mongos_load_balancing.py index 4ab4d30657..812a9072ff 100644 --- a/test/test_mongos_load_balancing.py +++ b/test/test_mongos_load_balancing.py @@ -89,7 +89,6 @@ def test_lazy_connect(self): # While connected() ensures we can trigger connection from the main # thread and wait for the monitors, this test triggers connection from # several threads at once to check for data races. - raise unittest.SkipTest("skip for now") nthreads = 10 client = self.mock_client() self.assertEqual(0, len(client.nodes)) diff --git a/test/test_read_preferences.py b/test/test_read_preferences.py index 4f774aa87d..da550e7db4 100644 --- a/test/test_read_preferences.py +++ b/test/test_read_preferences.py @@ -300,12 +300,6 @@ def _conn_from_server(self, read_preference, server, session): self.record_a_read(conn.address) yield conn, read_preference - async def _socket_for_reads_async(self, read_preference, session): - context = await super()._socket_for_reads_async(read_preference, session) - async with context as (sock_info, read_preference): - self.record_a_read(sock_info.address) - return await super()._socket_for_reads_async(read_preference, session) - def record_a_read(self, address): server = self._get_topology().select_server_by_address(address, _Op.TEST, 0) self.has_read_from.add(server) diff --git a/test/test_session.py b/test/test_session.py index f746c6d7cb..7098cec6fc 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -185,7 +185,6 @@ 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 - raise unittest.SkipTest("temporary skip") lsid_set = set() failures = 0 for _ in range(5): @@ -297,8 +296,8 @@ def test_client(self): client = self.client ops: list = [ (client.server_info, [], {}), - # (client.list_database_names, [], {}), - # (client.drop_database, ["pymongo_test"], {}), + (client.list_database_names, [], {}), + (client.drop_database, ["pymongo_test"], {}), ] self._test_ops(client, *ops)