Skip to content

Commit b0c878c

Browse files
committed
use ConcurrentRunner
1 parent 8b3f1a9 commit b0c878c

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

test/asynchronous/test_mongos_load_balancing.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async def test_lazy_connect(self):
101101
await async_wait_until(lambda: len(client.nodes) == 3, "connect to all mongoses")
102102

103103
async def test_failover(self):
104-
nthreads = 10
104+
ntasks = 10
105105
client = await connected(self.mock_client(localThresholdMS=0.001))
106106
await async_wait_until(lambda: len(client.nodes) == 3, "connect to all mongoses")
107107

@@ -121,19 +121,14 @@ async def f():
121121

122122
passed.append(True)
123123

124-
if _IS_SYNC:
125-
threads = [threading.Thread(target=f) for _ in range(nthreads)]
126-
for t in threads:
127-
t.start()
124+
tasks = [ConcurrentRunner(target=f) for _ in range(ntasks)]
125+
for t in tasks:
126+
await t.start()
128127

129-
for t in threads:
130-
t.join()
131-
else:
132-
tasks = [asyncio.create_task(f()) for _ in range(nthreads)]
133-
for t in tasks:
134-
await t
128+
for t in tasks:
129+
await t.join()
135130

136-
self.assertEqual(nthreads, len(passed))
131+
self.assertEqual(ntasks, len(passed))
137132

138133
# Down host removed from list.
139134
self.assertEqual(2, len(client.nodes))

test/test_mongos_load_balancing.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_lazy_connect(self):
101101
wait_until(lambda: len(client.nodes) == 3, "connect to all mongoses")
102102

103103
def test_failover(self):
104-
nthreads = 10
104+
ntasks = 10
105105
client = connected(self.mock_client(localThresholdMS=0.001))
106106
wait_until(lambda: len(client.nodes) == 3, "connect to all mongoses")
107107

@@ -121,19 +121,14 @@ def f():
121121

122122
passed.append(True)
123123

124-
if _IS_SYNC:
125-
threads = [threading.Thread(target=f) for _ in range(nthreads)]
126-
for t in threads:
127-
t.start()
124+
tasks = [ConcurrentRunner(target=f) for _ in range(ntasks)]
125+
for t in tasks:
126+
t.start()
128127

129-
for t in threads:
130-
t.join()
131-
else:
132-
tasks = [asyncio.create_task(f()) for _ in range(nthreads)]
133-
for t in tasks:
134-
t
128+
for t in tasks:
129+
t.join()
135130

136-
self.assertEqual(nthreads, len(passed))
131+
self.assertEqual(ntasks, len(passed))
137132

138133
# Down host removed from list.
139134
self.assertEqual(2, len(client.nodes))

0 commit comments

Comments
 (0)