MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_maxConnecting

Method test_maxConnecting

test/test_pooling.py:397–430  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

395 pool.close()
396
397 def test_maxConnecting(self):
398 client = self.rs_or_single_client()
399 self.client.test.test.insert_one({})
400 self.addCleanup(self.client.test.test.delete_many, {})
401 pool = get_pool(client)
402 docs = []
403
404 # Run 50 short running operations
405 def find_one():
406 docs.append(client.test.test.find_one({}))
407
408 tasks = [ConcurrentRunner(target=find_one) for _ in range(50)]
409 for task in tasks:
410 task.start()
411 for task in tasks:
412 task.join(10)
413
414 self.assertEqual(len(docs), 50)
415 self.assertLessEqual(len(pool.conns), 50)
416 # TLS and auth make connection establishment more expensive than
417 # the query which leads to more threads hitting maxConnecting.
418 # The end result is fewer total connections and better latency.
419 if client_context.tls and client_context.auth_enabled:
420 self.assertLessEqual(len(pool.conns), 30)
421 else:
422 self.assertLessEqual(len(pool.conns), 50)
423 # MongoDB 4.4.1 with auth + ssl:
424 # maxConnecting = 2: 6 connections in ~0.231+ seconds
425 # maxConnecting = unbounded: 50 connections in ~0.642+ seconds
426 #
427 # MongoDB 4.4.1 with no-auth no-ssl Python 3.8:
428 # maxConnecting = 2: 15-22 connections in ~0.108+ seconds
429 # maxConnecting = unbounded: 30+ connections in ~0.140+ seconds
430 print(len(pool.conns))
431
432 @client_context.require_failCommand_appName
433 def test_csot_timeout_message(self):

Callers

nothing calls this directly

Calls 7

get_poolFunction · 0.90
ConcurrentRunnerClass · 0.90
rs_or_single_clientMethod · 0.80
addCleanupMethod · 0.80
insert_oneMethod · 0.45
startMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected