(self)
| 2508 | self.assertLess(len(c.nodes), 3) |
| 2509 | |
| 2510 | def test_reconnect(self): |
| 2511 | # Verify the node list isn't forgotten during a network failure. |
| 2512 | c = MockClient.get_mock_client( |
| 2513 | standalones=[], |
| 2514 | members=["a:1", "b:2", "c:3"], |
| 2515 | mongoses=[], |
| 2516 | host="b:2", # Pass a secondary. |
| 2517 | replicaSet="rs", |
| 2518 | retryReads=False, |
| 2519 | serverSelectionTimeoutMS=1000, |
| 2520 | ) |
| 2521 | self.addCleanup(c.close) |
| 2522 | |
| 2523 | wait_until(lambda: len(c.nodes) == 3, "connect") |
| 2524 | |
| 2525 | # Total failure. |
| 2526 | c.kill_host("a:1") |
| 2527 | c.kill_host("b:2") |
| 2528 | c.kill_host("c:3") |
| 2529 | |
| 2530 | # MongoClient discovers it's alone. The first attempt raises either |
| 2531 | # ServerSelectionTimeoutError or AutoReconnect (from |
| 2532 | # MockPool.get_socket). |
| 2533 | with self.assertRaises(AutoReconnect): |
| 2534 | c.db.collection.find_one() |
| 2535 | |
| 2536 | # But it can reconnect. |
| 2537 | c.revive_host("a:1") |
| 2538 | (c._get_topology()).select_servers( |
| 2539 | writable_server_selector, _Op.TEST, server_selection_timeout=10 |
| 2540 | ) |
| 2541 | self.assertEqual(c.address, ("a", 1)) |
| 2542 | |
| 2543 | def _test_network_error(self, operation_callback): |
| 2544 | # Verify only the disconnected server is reset by a network failure. |
nothing calls this directly
no test coverage detected