PYTHON-2924 Improve test_load_balancing (#955)
This commit is contained in:
parent
cf08d46ff9
commit
09385be549
@ -17,7 +17,13 @@
|
||||
import os
|
||||
import threading
|
||||
from test import IntegrationTest, client_context, unittest
|
||||
from test.utils import OvertCommandListener, TestCreator, rs_client, wait_until
|
||||
from test.utils import (
|
||||
OvertCommandListener,
|
||||
TestCreator,
|
||||
get_pool,
|
||||
rs_client,
|
||||
wait_until,
|
||||
)
|
||||
from test.utils_selection_tests import create_topology
|
||||
|
||||
from pymongo.common import clean_node
|
||||
@ -98,11 +104,10 @@ class FinderThread(threading.Thread):
|
||||
|
||||
|
||||
class TestProse(IntegrationTest):
|
||||
def frequencies(self, client, listener):
|
||||
def frequencies(self, client, listener, n_finds=10):
|
||||
coll = client.test.test
|
||||
N_FINDS = 10
|
||||
N_THREADS = 10
|
||||
threads = [FinderThread(coll, N_FINDS) for _ in range(N_THREADS)]
|
||||
threads = [FinderThread(coll, n_finds) for _ in range(N_THREADS)]
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
@ -111,7 +116,7 @@ class TestProse(IntegrationTest):
|
||||
self.assertTrue(thread.passed)
|
||||
|
||||
events = listener.results["started"]
|
||||
self.assertEqual(len(events), N_FINDS * N_THREADS)
|
||||
self.assertEqual(len(events), n_finds * N_THREADS)
|
||||
nodes = client.nodes
|
||||
self.assertEqual(len(nodes), 2)
|
||||
freqs = {address: 0.0 for address in nodes}
|
||||
@ -131,10 +136,12 @@ class TestProse(IntegrationTest):
|
||||
client_context.mongos_seeds(),
|
||||
appName="loadBalancingTest",
|
||||
event_listeners=[listener],
|
||||
localThresholdMS=10000,
|
||||
localThresholdMS=30000,
|
||||
minPoolSize=10,
|
||||
)
|
||||
self.addCleanup(client.close)
|
||||
wait_until(lambda: len(client.nodes) == 2, "discover both nodes")
|
||||
wait_until(lambda: len(get_pool(client).sockets) >= 10, "create 10 connections")
|
||||
# Delay find commands on
|
||||
delay_finds = {
|
||||
"configureFailPoint": "failCommand",
|
||||
@ -153,7 +160,7 @@ class TestProse(IntegrationTest):
|
||||
freqs = self.frequencies(client, listener)
|
||||
self.assertLessEqual(freqs[delayed_server], 0.25)
|
||||
listener.reset()
|
||||
freqs = self.frequencies(client, listener)
|
||||
freqs = self.frequencies(client, listener, n_finds=100)
|
||||
self.assertAlmostEqual(freqs[delayed_server], 0.50, delta=0.15)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user