1717import os
1818import threading
1919from test import IntegrationTest , client_context , unittest
20- from test .utils import OvertCommandListener , TestCreator , rs_client , wait_until
20+ from test .utils import (
21+ OvertCommandListener ,
22+ TestCreator ,
23+ get_pool ,
24+ rs_client ,
25+ wait_until ,
26+ )
2127from test .utils_selection_tests import create_topology
2228
2329from pymongo .common import clean_node
@@ -98,11 +104,10 @@ def run(self):
98104
99105
100106class TestProse (IntegrationTest ):
101- def frequencies (self , client , listener ):
107+ def frequencies (self , client , listener , n_finds = 10 ):
102108 coll = client .test .test
103- N_FINDS = 10
104109 N_THREADS = 10
105- threads = [FinderThread (coll , N_FINDS ) for _ in range (N_THREADS )]
110+ threads = [FinderThread (coll , n_finds ) for _ in range (N_THREADS )]
106111 for thread in threads :
107112 thread .start ()
108113 for thread in threads :
@@ -111,7 +116,7 @@ def frequencies(self, client, listener):
111116 self .assertTrue (thread .passed )
112117
113118 events = listener .results ["started" ]
114- self .assertEqual (len (events ), N_FINDS * N_THREADS )
119+ self .assertEqual (len (events ), n_finds * N_THREADS )
115120 nodes = client .nodes
116121 self .assertEqual (len (nodes ), 2 )
117122 freqs = {address : 0.0 for address in nodes }
@@ -131,10 +136,12 @@ def test_load_balancing(self):
131136 client_context .mongos_seeds (),
132137 appName = "loadBalancingTest" ,
133138 event_listeners = [listener ],
134- localThresholdMS = 10000 ,
139+ localThresholdMS = 30000 ,
140+ minPoolSize = 10 ,
135141 )
136142 self .addCleanup (client .close )
137143 wait_until (lambda : len (client .nodes ) == 2 , "discover both nodes" )
144+ wait_until (lambda : len (get_pool (client ).sockets ) >= 10 , "create 10 connections" )
138145 # Delay find commands on
139146 delay_finds = {
140147 "configureFailPoint" : "failCommand" ,
@@ -153,7 +160,7 @@ def test_load_balancing(self):
153160 freqs = self .frequencies (client , listener )
154161 self .assertLessEqual (freqs [delayed_server ], 0.25 )
155162 listener .reset ()
156- freqs = self .frequencies (client , listener )
163+ freqs = self .frequencies (client , listener , n_finds = 100 )
157164 self .assertAlmostEqual (freqs [delayed_server ], 0.50 , delta = 0.15 )
158165
159166
0 commit comments