Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PYTHON-4503 - Re-enable accidentally disabled tests #1683

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 17 additions & 36 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -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",
Expand All @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand Down Expand Up @@ -1550,33 +1541,25 @@ 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)

# 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)
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion test/test_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions test/test_gridfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 0 additions & 1 deletion test/test_mongos_load_balancing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 0 additions & 6 deletions test/test_read_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Comment on lines -303 to -308
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I"m guessing this is now unneeded/unused?

def record_a_read(self, address):
server = self._get_topology().select_server_by_address(address, _Op.TEST, 0)
self.has_read_from.add(server)
Expand Down
5 changes: 2 additions & 3 deletions test/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
Loading