30
30
import sys
31
31
import threading
32
32
import time
33
- import warnings
34
33
from typing import Iterable , Type , no_type_check
35
34
from unittest import mock
36
35
from unittest .mock import patch
@@ -617,7 +616,7 @@ def test_max_idle_time_reaper_default(self):
617
616
with client_knobs (kill_cursor_frequency = 0.1 ):
618
617
# Assert reaper doesn't remove connections when maxIdleTimeMS not set
619
618
client = rs_or_single_client ()
620
- server = client ._get_topology ()._select_server (readable_server_selector , _Op .TEST )
619
+ server = client ._get_topology ().select_server (readable_server_selector , _Op .TEST )
621
620
with server ._pool .checkout () as conn :
622
621
pass
623
622
self .assertEqual (1 , len (server ._pool .conns ))
@@ -628,7 +627,7 @@ def test_max_idle_time_reaper_removes_stale_minPoolSize(self):
628
627
with client_knobs (kill_cursor_frequency = 0.1 ):
629
628
# Assert reaper removes idle socket and replaces it with a new one
630
629
client = rs_or_single_client (maxIdleTimeMS = 500 , minPoolSize = 1 )
631
- server = client ._get_topology ()._select_server (readable_server_selector , _Op .TEST )
630
+ server = client ._get_topology ().select_server (readable_server_selector , _Op .TEST )
632
631
with server ._pool .checkout () as conn :
633
632
pass
634
633
# 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):
642
641
with client_knobs (kill_cursor_frequency = 0.1 ):
643
642
# Assert reaper respects maxPoolSize when adding new connections.
644
643
client = rs_or_single_client (maxIdleTimeMS = 500 , minPoolSize = 1 , maxPoolSize = 1 )
645
- server = client ._get_topology ()._select_server (readable_server_selector , _Op .TEST )
644
+ server = client ._get_topology ().select_server (readable_server_selector , _Op .TEST )
646
645
with server ._pool .checkout () as conn :
647
646
pass
648
647
# 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):
656
655
with client_knobs (kill_cursor_frequency = 0.1 ):
657
656
# Assert reaper has removed idle socket and NOT replaced it
658
657
client = rs_or_single_client (maxIdleTimeMS = 500 )
659
- server = client ._get_topology ()._select_server (readable_server_selector , _Op .TEST )
658
+ server = client ._get_topology ().select_server (readable_server_selector , _Op .TEST )
660
659
with server ._pool .checkout () as conn_one :
661
660
pass
662
661
# Assert that the pool does not close connections prematurely.
@@ -673,12 +672,12 @@ def test_max_idle_time_reaper_removes_stale(self):
673
672
def test_min_pool_size (self ):
674
673
with client_knobs (kill_cursor_frequency = 0.1 ):
675
674
client = rs_or_single_client ()
676
- server = client ._get_topology ()._select_server (readable_server_selector , _Op .TEST )
675
+ server = client ._get_topology ().select_server (readable_server_selector , _Op .TEST )
677
676
self .assertEqual (0 , len (server ._pool .conns ))
678
677
679
678
# Assert that pool started up at minPoolSize
680
679
client = rs_or_single_client (minPoolSize = 10 )
681
- server = client ._get_topology ()._select_server (readable_server_selector , _Op .TEST )
680
+ server = client ._get_topology ().select_server (readable_server_selector , _Op .TEST )
682
681
wait_until (
683
682
lambda : len (server ._pool .conns ) == 10 ,
684
683
"pool initialized with 10 connections" ,
@@ -697,7 +696,7 @@ def test_max_idle_time_checkout(self):
697
696
# Use high frequency to test _get_socket_no_auth.
698
697
with client_knobs (kill_cursor_frequency = 99999999 ):
699
698
client = rs_or_single_client (maxIdleTimeMS = 500 )
700
- server = client ._get_topology ()._select_server (readable_server_selector , _Op .TEST )
699
+ server = client ._get_topology ().select_server (readable_server_selector , _Op .TEST )
701
700
with server ._pool .checkout () as conn :
702
701
pass
703
702
self .assertEqual (1 , len (server ._pool .conns ))
@@ -711,7 +710,7 @@ def test_max_idle_time_checkout(self):
711
710
712
711
# Test that connections are reused if maxIdleTimeMS is not set.
713
712
client = rs_or_single_client ()
714
- server = client ._get_topology ()._select_server (readable_server_selector , _Op .TEST )
713
+ server = client ._get_topology ().select_server (readable_server_selector , _Op .TEST )
715
714
with server ._pool .checkout () as conn :
716
715
pass
717
716
self .assertEqual (1 , len (server ._pool .conns ))
@@ -1180,9 +1179,7 @@ def test_server_selection_timeout(self):
1180
1179
client = MongoClient (serverSelectionTimeoutMS = 100 , connect = False )
1181
1180
self .assertAlmostEqual (0.1 , client .options .server_selection_timeout )
1182
1181
1183
- with warnings .catch_warnings ():
1184
- warnings .simplefilter ("ignore" , UserWarning )
1185
- client = MongoClient (serverSelectionTimeoutMS = 0 , connect = False )
1182
+ client = MongoClient (serverSelectionTimeoutMS = 0 , connect = False )
1186
1183
1187
1184
self .assertAlmostEqual (0 , client .options .server_selection_timeout )
1188
1185
@@ -1195,20 +1192,14 @@ def test_server_selection_timeout(self):
1195
1192
client = MongoClient ("mongodb://localhost/?serverSelectionTimeoutMS=100" , connect = False )
1196
1193
self .assertAlmostEqual (0.1 , client .options .server_selection_timeout )
1197
1194
1198
- with warnings .catch_warnings ():
1199
- warnings .simplefilter ("ignore" , UserWarning )
1200
- client = MongoClient ("mongodb://localhost/?serverSelectionTimeoutMS=0" , connect = False )
1195
+ client = MongoClient ("mongodb://localhost/?serverSelectionTimeoutMS=0" , connect = False )
1201
1196
self .assertAlmostEqual (0 , client .options .server_selection_timeout )
1202
1197
1203
1198
# Test invalid timeout in URI ignored and set to default.
1204
- with warnings .catch_warnings ():
1205
- warnings .simplefilter ("ignore" , UserWarning )
1206
- client = MongoClient ("mongodb://localhost/?serverSelectionTimeoutMS=-1" , connect = False )
1199
+ client = MongoClient ("mongodb://localhost/?serverSelectionTimeoutMS=-1" , connect = False )
1207
1200
self .assertAlmostEqual (30 , client .options .server_selection_timeout )
1208
1201
1209
- with warnings .catch_warnings ():
1210
- warnings .simplefilter ("ignore" , UserWarning )
1211
- client = MongoClient ("mongodb://localhost/?serverSelectionTimeoutMS=" , connect = False )
1202
+ client = MongoClient ("mongodb://localhost/?serverSelectionTimeoutMS=" , connect = False )
1212
1203
self .assertAlmostEqual (30 , client .options .server_selection_timeout )
1213
1204
1214
1205
def test_waitQueueTimeoutMS (self ):
@@ -1550,33 +1541,25 @@ def compression_settings(client):
1550
1541
self .assertEqual (opts .compressors , [])
1551
1542
self .assertEqual (opts .zlib_compression_level , - 1 )
1552
1543
uri = "mongodb://localhost:27017/?compressors=foobar"
1553
- with warnings .catch_warnings ():
1554
- warnings .simplefilter ("ignore" , UserWarning )
1555
- client = MongoClient (uri , connect = False )
1544
+ client = MongoClient (uri , connect = False )
1556
1545
opts = compression_settings (client )
1557
1546
self .assertEqual (opts .compressors , [])
1558
1547
self .assertEqual (opts .zlib_compression_level , - 1 )
1559
1548
uri = "mongodb://localhost:27017/?compressors=foobar,zlib"
1560
- with warnings .catch_warnings ():
1561
- warnings .simplefilter ("ignore" , UserWarning )
1562
- client = MongoClient (uri , connect = False )
1549
+ client = MongoClient (uri , connect = False )
1563
1550
opts = compression_settings (client )
1564
1551
self .assertEqual (opts .compressors , ["zlib" ])
1565
1552
self .assertEqual (opts .zlib_compression_level , - 1 )
1566
1553
1567
1554
# According to the connection string spec, unsupported values
1568
1555
# just raise a warning and are ignored.
1569
1556
uri = "mongodb://localhost:27017/?compressors=zlib&zlibCompressionLevel=10"
1570
- with warnings .catch_warnings ():
1571
- warnings .simplefilter ("ignore" , UserWarning )
1572
- client = MongoClient (uri , connect = False )
1557
+ client = MongoClient (uri , connect = False )
1573
1558
opts = compression_settings (client )
1574
1559
self .assertEqual (opts .compressors , ["zlib" ])
1575
1560
self .assertEqual (opts .zlib_compression_level , - 1 )
1576
1561
uri = "mongodb://localhost:27017/?compressors=zlib&zlibCompressionLevel=-2"
1577
- with warnings .catch_warnings ():
1578
- warnings .simplefilter ("ignore" , UserWarning )
1579
- client = MongoClient (uri , connect = False )
1562
+ client = MongoClient (uri , connect = False )
1580
1563
opts = compression_settings (client )
1581
1564
self .assertEqual (opts .compressors , ["zlib" ])
1582
1565
self .assertEqual (opts .zlib_compression_level , - 1 )
@@ -1598,9 +1581,7 @@ def compression_settings(client):
1598
1581
1599
1582
if not _have_zstd ():
1600
1583
uri = "mongodb://localhost:27017/?compressors=zstd"
1601
- with warnings .catch_warnings ():
1602
- warnings .simplefilter ("ignore" , UserWarning )
1603
- client = MongoClient (uri , connect = False )
1584
+ client = MongoClient (uri , connect = False )
1604
1585
opts = compression_settings (client )
1605
1586
self .assertEqual (opts .compressors , [])
1606
1587
else :
0 commit comments