MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / test_reset_during_update_pool

Method test_reset_during_update_pool

test/test_client.py:1772–1812  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1770
1771 @client_context.require_sync
1772 def test_reset_during_update_pool(self):
1773 client = self.rs_or_single_client(minPoolSize=10)
1774 client.admin.command("ping")
1775 pool = get_pool(client)
1776 generation = pool.gen.get_overall()
1777
1778 # Continuously reset the pool.
1779 class ResetPoolThread(threading.Thread):
1780 def __init__(self, pool):
1781 super().__init__()
1782 self.running = True
1783 self.pool = pool
1784
1785 def stop(self):
1786 self.running = False
1787
1788 def _run(self):
1789 while self.running:
1790 exc = AutoReconnect("mock pool error")
1791 ctx = _ErrorContext(exc, 0, pool.gen.get_overall(), False, None)
1792 client._topology.handle_error(pool.address, ctx)
1793 time.sleep(0.001)
1794
1795 def run(self):
1796 self._run()
1797
1798 t = ResetPoolThread(pool)
1799 t.start()
1800
1801 # Ensure that update_pool completes without error even when the pool
1802 # is reset concurrently.
1803 try:
1804 while True:
1805 for _ in range(10):
1806 client._topology.update_pool()
1807 if generation != pool.gen.get_overall():
1808 break
1809 finally:
1810 t.stop()
1811 t.join()
1812 client.admin.command("ping")
1813
1814 def test_background_connections_do_not_hold_locks(self):
1815 min_pool_size = 10

Callers

nothing calls this directly

Calls 9

stopMethod · 0.95
get_poolFunction · 0.90
rs_or_single_clientMethod · 0.80
ResetPoolThreadClass · 0.70
commandMethod · 0.45
get_overallMethod · 0.45
startMethod · 0.45
update_poolMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected