File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -719,8 +719,6 @@ def __init__(
719
719
direct_connection = options .direct_connection )
720
720
721
721
self ._topology = Topology (self ._topology_settings )
722
- if connect :
723
- self ._topology .open ()
724
722
725
723
def target ():
726
724
client = self_ref ()
@@ -739,7 +737,9 @@ def target():
739
737
# this closure. When the client is freed, stop the executor soon.
740
738
self_ref = weakref .ref (self , executor .close )
741
739
self ._kill_cursors_executor = executor
742
- executor .open ()
740
+
741
+ if connect :
742
+ self ._get_topology ()
743
743
744
744
self ._encrypter = None
745
745
if self .__options .auto_encryption_opts :
Original file line number Diff line number Diff line change @@ -790,6 +790,24 @@ def test_close_stops_kill_cursors_thread(self):
790
790
client .close ()
791
791
self .assertTrue (client ._kill_cursors_executor ._stopped )
792
792
793
+ def test_uri_connect_option (self ):
794
+ # Ensure that topology is not opened if connect=False.
795
+ client = rs_client (connect = False )
796
+ self .assertFalse (client ._topology ._opened )
797
+
798
+ # Ensure kill cursors thread has not been started.
799
+ kc_thread = client ._kill_cursors_executor ._thread
800
+ self .assertFalse (kc_thread and kc_thread .is_alive ())
801
+
802
+ # Using the client should open topology and start the thread.
803
+ client .admin .command ('isMaster' )
804
+ self .assertTrue (client ._topology ._opened )
805
+ kc_thread = client ._kill_cursors_executor ._thread
806
+ self .assertTrue (kc_thread and kc_thread .is_alive ())
807
+
808
+ # Tear down.
809
+ client .close ()
810
+
793
811
def test_close_does_not_open_servers (self ):
794
812
client = rs_client (connect = False )
795
813
topology = client ._topology
You can’t perform that action at this time.
0 commit comments