@@ -633,22 +633,38 @@ def test_read_preference_from_parse(self):
633633 assert conn .read_preference == ReadPreference .SECONDARY_PREFERRED
634634
635635 def test_multiple_connection_settings (self ):
636- connect ("mongoenginetest" , alias = "t1" , host = "localhost" )
637-
638- connect ("mongoenginetest2" , alias = "t2" , host = "127.0.0.1" )
636+ connect (
637+ "mongoenginetest" ,
638+ alias = "t1" ,
639+ host = "localhost" ,
640+ read_preference = ReadPreference .PRIMARY ,
641+ )
642+ connect (
643+ "mongoenginetest2" ,
644+ alias = "t2" ,
645+ host = "127.0.0.1" ,
646+ read_preference = ReadPreference .PRIMARY_PREFERRED ,
647+ )
639648
640649 mongo_connections = mongoengine .connection ._connections
641650 assert len (mongo_connections .items ()) == 2
642651 assert "t1" in mongo_connections .keys ()
643652 assert "t2" in mongo_connections .keys ()
644653
645- # Handle PyMongo 3+ Async Connection
654+ # Handle PyMongo 3+ Async Connection (lazily established)
646655 # Ensure we are connected, throws ServerSelectionTimeoutError otherwise.
647656 # Purposely not catching exception to fail test if thrown.
648657 mongo_connections ["t1" ].server_info ()
649658 mongo_connections ["t2" ].server_info ()
659+
650660 assert mongo_connections ["t1" ].address [0 ] == "localhost"
651- assert mongo_connections ["t2" ].address [0 ] == "127.0.0.1"
661+ assert (
662+ mongo_connections ["t2" ].address [0 ] == "localhost"
663+ ) # weird but we have this with replicaset
664+ assert mongo_connections ["t1" ].read_preference == ReadPreference .PRIMARY
665+ assert (
666+ mongo_connections ["t2" ].read_preference == ReadPreference .PRIMARY_PREFERRED
667+ )
652668 assert mongo_connections ["t1" ] is not mongo_connections ["t2" ]
653669
654670 def test_connect_2_databases_uses_same_client_if_only_dbname_differs (self ):
0 commit comments