1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
|
Description: Delete broken tests
Author: Salvo 'LtWorf' Tomaselli <ltworf@debian.org>
Forwarded: no
Last-Update: 2024-10-14
--- a/test/test_srv_polling.py
+++ b/test/test_srv_polling.py
@@ -35,353 +35,3 @@
_IS_SYNC = True
WAIT_TIME = 0.1
-
-
-class SrvPollingKnobs:
- def __init__(
- self,
- ttl_time=None,
- min_srv_rescan_interval=None,
- nodelist_callback=None,
- count_resolver_calls=False,
- ):
- self.ttl_time = ttl_time
- self.min_srv_rescan_interval = min_srv_rescan_interval
- self.nodelist_callback = nodelist_callback
- self.count_resolver_calls = count_resolver_calls
-
- self.old_min_srv_rescan_interval = None
- self.old_dns_resolver_response = None
-
- def enable(self):
- self.old_min_srv_rescan_interval = common.MIN_SRV_RESCAN_INTERVAL
- self.old_dns_resolver_response = (
- pymongo.synchronous.srv_resolver._SrvResolver.get_hosts_and_min_ttl
- )
-
- if self.min_srv_rescan_interval is not None:
- common.MIN_SRV_RESCAN_INTERVAL = self.min_srv_rescan_interval
-
- def mock_get_hosts_and_min_ttl(resolver, *args):
- assert self.old_dns_resolver_response is not None
- nodes, ttl = self.old_dns_resolver_response(resolver)
- if self.nodelist_callback is not None:
- nodes = self.nodelist_callback()
- if self.ttl_time is not None:
- ttl = self.ttl_time
- return nodes, ttl
-
- patch_func: Any
- if self.count_resolver_calls:
- patch_func = FunctionCallRecorder(mock_get_hosts_and_min_ttl)
- else:
- patch_func = mock_get_hosts_and_min_ttl
-
- pymongo.synchronous.srv_resolver._SrvResolver.get_hosts_and_min_ttl = patch_func # type: ignore
-
- def __enter__(self):
- self.enable()
-
- def disable(self):
- common.MIN_SRV_RESCAN_INTERVAL = self.old_min_srv_rescan_interval # type: ignore
- pymongo.synchronous.srv_resolver._SrvResolver.get_hosts_and_min_ttl = ( # type: ignore
- self.old_dns_resolver_response
- )
-
- def __exit__(self, exc_type, exc_val, exc_tb):
- self.disable()
-
-
-class TestSrvPolling(PyMongoTestCase):
- BASE_SRV_RESPONSE = [
- ("localhost.test.build.10gen.cc", 27017),
- ("localhost.test.build.10gen.cc", 27018),
- ]
-
- CONNECTION_STRING = "mongodb+srv://test1.test.build.10gen.cc"
-
- def setUp(self):
- # Patch timeouts to ensure short rescan SRV interval.
- self.client_knobs = client_knobs(
- heartbeat_frequency=WAIT_TIME,
- min_heartbeat_interval=WAIT_TIME,
- events_queue_frequency=WAIT_TIME,
- )
- self.client_knobs.enable()
-
- def tearDown(self):
- self.client_knobs.disable()
-
- def get_nodelist(self, client):
- return client._topology.description.server_descriptions().keys()
-
- def assert_nodelist_change(self, expected_nodelist, client, timeout=(100 * WAIT_TIME)):
- """Check if the client._topology eventually sees all nodes in the
- expected_nodelist.
- """
-
- def predicate():
- nodelist = self.get_nodelist(client)
- if set(expected_nodelist) == set(nodelist):
- return True
- return False
-
- wait_until(predicate, "see expected nodelist", timeout=timeout)
-
- def assert_nodelist_nochange(self, expected_nodelist, client, timeout=(100 * WAIT_TIME)):
- """Check if the client._topology ever deviates from seeing all nodes
- in the expected_nodelist. Consistency is checked after sleeping for
- (WAIT_TIME * 10) seconds. Also check that the resolver is called at
- least once.
- """
-
- def predicate():
- if set(expected_nodelist) == set(self.get_nodelist(client)):
- return (
- pymongo.synchronous.srv_resolver._SrvResolver.get_hosts_and_min_ttl.call_count
- >= 1
- )
- return False
-
- wait_until(predicate, "Node list equals expected nodelist", timeout=timeout)
-
- nodelist = self.get_nodelist(client)
- if set(expected_nodelist) != set(nodelist):
- msg = "Client nodelist %s changed unexpectedly (expected %s)"
- raise self.fail(msg % (nodelist, expected_nodelist))
- self.assertGreaterEqual(
- pymongo.synchronous.srv_resolver._SrvResolver.get_hosts_and_min_ttl.call_count, # type: ignore
- 1,
- "resolver was never called",
- )
- return True
-
- def run_scenario(self, dns_response, expect_change):
- self.assertEqual(_have_dnspython(), True)
- if callable(dns_response):
- dns_resolver_response = dns_response
- else:
-
- def dns_resolver_response():
- return dns_response
-
- if expect_change:
- assertion_method = self.assert_nodelist_change
- count_resolver_calls = False
- expected_response = dns_response
- else:
- assertion_method = self.assert_nodelist_nochange
- count_resolver_calls = True
- expected_response = self.BASE_SRV_RESPONSE
-
- # Patch timeouts to ensure short test running times.
- with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
- client = self.simple_client(self.CONNECTION_STRING)
- client._connect()
- self.assert_nodelist_change(self.BASE_SRV_RESPONSE, client)
- # Patch list of hosts returned by DNS query.
- with SrvPollingKnobs(
- nodelist_callback=dns_resolver_response, count_resolver_calls=count_resolver_calls
- ):
- assertion_method(expected_response, client)
-
- # Close the client early to avoid affecting the next scenario run.
- client.close()
-
- def test_addition(self):
- response = self.BASE_SRV_RESPONSE[:]
- response.append(("localhost.test.build.10gen.cc", 27019))
- self.run_scenario(response, True)
-
- def test_removal(self):
- response = self.BASE_SRV_RESPONSE[:]
- response.remove(("localhost.test.build.10gen.cc", 27018))
- self.run_scenario(response, True)
-
- def test_replace_one(self):
- response = self.BASE_SRV_RESPONSE[:]
- response.remove(("localhost.test.build.10gen.cc", 27018))
- response.append(("localhost.test.build.10gen.cc", 27019))
- self.run_scenario(response, True)
-
- def test_replace_both_with_one(self):
- response = [("localhost.test.build.10gen.cc", 27019)]
- self.run_scenario(response, True)
-
- def test_replace_both_with_two(self):
- response = [
- ("localhost.test.build.10gen.cc", 27019),
- ("localhost.test.build.10gen.cc", 27020),
- ]
- self.run_scenario(response, True)
-
- def test_dns_failures(self):
- from dns import exception
-
- for exc in (exception.FormError, exception.TooBig, exception.Timeout):
-
- def response_callback(*args):
- raise exc("DNS Failure!")
-
- self.run_scenario(response_callback, False)
-
- @flaky(reason="PYTHON-5500")
- def test_dns_failures_logging(self):
- from dns import exception
-
- with self.assertLogs("pymongo.topology", level="DEBUG") as cm:
-
- def response_callback(*args):
- raise exception.Timeout("DNS Failure!")
-
- self.run_scenario(response_callback, False)
-
- srv_failure_logs = [r for r in cm.records if "SRV monitor check failed" in r.getMessage()]
- self.assertEqual(len(srv_failure_logs), 1)
-
- def test_dns_record_lookup_empty(self):
- response: list = []
- self.run_scenario(response, False)
-
- def _test_recover_from_initial(self, initial_callback):
- # Construct a valid final response callback distinct from base.
- response_final = self.BASE_SRV_RESPONSE[:]
- response_final.pop()
-
- def final_callback():
- return response_final
-
- with SrvPollingKnobs(
- ttl_time=WAIT_TIME,
- min_srv_rescan_interval=WAIT_TIME,
- nodelist_callback=initial_callback,
- count_resolver_calls=True,
- ):
- # Client uses unpatched method to get initial nodelist
- client = self.simple_client(self.CONNECTION_STRING)
- client._connect()
- # Invalid DNS resolver response should not change nodelist.
- self.assert_nodelist_nochange(self.BASE_SRV_RESPONSE, client)
-
- with SrvPollingKnobs(
- ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME, nodelist_callback=final_callback
- ):
- # Nodelist should reflect new valid DNS resolver response.
- self.assert_nodelist_change(response_final, client)
-
- @flaky(reason="PYTHON-5315")
- def test_recover_from_initially_empty_seedlist(self):
- def empty_seedlist():
- return []
-
- self._test_recover_from_initial(empty_seedlist)
-
- @flaky(reason="PYTHON-5315")
- def test_recover_from_initially_erroring_seedlist(self):
- def erroring_seedlist():
- raise ConfigurationError
-
- self._test_recover_from_initial(erroring_seedlist)
-
- def test_10_all_dns_selected(self):
- response = [
- ("localhost.test.build.10gen.cc", 27017),
- ("localhost.test.build.10gen.cc", 27019),
- ("localhost.test.build.10gen.cc", 27020),
- ]
-
- def nodelist_callback():
- return response
-
- with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
- client = self.simple_client(self.CONNECTION_STRING, srvMaxHosts=0)
- client._connect()
- with SrvPollingKnobs(nodelist_callback=nodelist_callback):
- self.assert_nodelist_change(response, client)
-
- def test_11_all_dns_selected(self):
- response = [
- ("localhost.test.build.10gen.cc", 27019),
- ("localhost.test.build.10gen.cc", 27020),
- ]
-
- def nodelist_callback():
- return response
-
- with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
- client = self.simple_client(self.CONNECTION_STRING, srvMaxHosts=2)
- client._connect()
- with SrvPollingKnobs(nodelist_callback=nodelist_callback):
- self.assert_nodelist_change(response, client)
-
- def test_12_new_dns_randomly_selected(self):
- response = [
- ("localhost.test.build.10gen.cc", 27020),
- ("localhost.test.build.10gen.cc", 27019),
- ("localhost.test.build.10gen.cc", 27017),
- ]
-
- def nodelist_callback():
- return response
-
- with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
- client = self.simple_client(self.CONNECTION_STRING, srvMaxHosts=2)
- client._connect()
- with SrvPollingKnobs(nodelist_callback=nodelist_callback):
- time.sleep(2 * common.MIN_SRV_RESCAN_INTERVAL)
- final_topology = set(client.topology_description.server_descriptions())
- self.assertIn(("localhost.test.build.10gen.cc", 27017), final_topology)
- self.assertEqual(len(final_topology), 2)
-
- def test_does_not_flipflop(self):
- with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
- client = self.simple_client(self.CONNECTION_STRING, srvMaxHosts=1)
- client._connect()
- old = set(client.topology_description.server_descriptions())
- time.sleep(4 * WAIT_TIME)
- new = set(client.topology_description.server_descriptions())
- self.assertSetEqual(old, new)
-
- def test_srv_service_name(self):
- # Construct a valid final response callback distinct from base.
- response = [
- ("localhost.test.build.10gen.cc.", 27019),
- ("localhost.test.build.10gen.cc.", 27020),
- ]
-
- def nodelist_callback():
- return response
-
- with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
- client = self.simple_client(
- "mongodb+srv://test22.test.build.10gen.cc/?srvServiceName=customname"
- )
- client._connect()
- with SrvPollingKnobs(nodelist_callback=nodelist_callback):
- self.assert_nodelist_change(response, client)
-
- def test_srv_waits_to_poll(self):
- modified = [("localhost.test.build.10gen.cc", 27019)]
-
- def resolver_response():
- return modified
-
- with SrvPollingKnobs(
- ttl_time=WAIT_TIME,
- min_srv_rescan_interval=WAIT_TIME,
- nodelist_callback=resolver_response,
- ):
- client = self.simple_client(self.CONNECTION_STRING)
- client._connect()
- with self.assertRaises(AssertionError):
- self.assert_nodelist_change(modified, client, timeout=WAIT_TIME / 2)
-
- def test_import_dns_resolver(self):
- # Regression test for PYTHON-4407
- import dns.resolver
-
- self.assertTrue(hasattr(dns.resolver, "resolve") or hasattr(dns.resolver, "query"))
-
-
-if __name__ == "__main__":
- unittest.main()
--- a/test/asynchronous/test_srv_polling.py
+++ b/test/asynchronous/test_srv_polling.py
@@ -90,298 +90,3 @@
def __exit__(self, exc_type, exc_val, exc_tb):
self.disable()
-
-
-class TestSrvPolling(AsyncPyMongoTestCase):
- BASE_SRV_RESPONSE = [
- ("localhost.test.build.10gen.cc", 27017),
- ("localhost.test.build.10gen.cc", 27018),
- ]
-
- CONNECTION_STRING = "mongodb+srv://test1.test.build.10gen.cc"
-
- async def asyncSetUp(self):
- # Patch timeouts to ensure short rescan SRV interval.
- self.client_knobs = client_knobs(
- heartbeat_frequency=WAIT_TIME,
- min_heartbeat_interval=WAIT_TIME,
- events_queue_frequency=WAIT_TIME,
- )
- self.client_knobs.enable()
-
- async def asyncTearDown(self):
- self.client_knobs.disable()
-
- def get_nodelist(self, client):
- return client._topology.description.server_descriptions().keys()
-
- async def assert_nodelist_change(self, expected_nodelist, client, timeout=(100 * WAIT_TIME)):
- """Check if the client._topology eventually sees all nodes in the
- expected_nodelist.
- """
-
- def predicate():
- nodelist = self.get_nodelist(client)
- if set(expected_nodelist) == set(nodelist):
- return True
- return False
-
- await async_wait_until(predicate, "see expected nodelist", timeout=timeout)
-
- async def assert_nodelist_nochange(self, expected_nodelist, client, timeout=(100 * WAIT_TIME)):
- """Check if the client._topology ever deviates from seeing all nodes
- in the expected_nodelist. Consistency is checked after sleeping for
- (WAIT_TIME * 10) seconds. Also check that the resolver is called at
- least once.
- """
-
- def predicate():
- if set(expected_nodelist) == set(self.get_nodelist(client)):
- return (
- pymongo.asynchronous.srv_resolver._SrvResolver.get_hosts_and_min_ttl.call_count
- >= 1
- )
- return False
-
- await async_wait_until(predicate, "Node list equals expected nodelist", timeout=timeout)
-
- nodelist = self.get_nodelist(client)
- if set(expected_nodelist) != set(nodelist):
- msg = "Client nodelist %s changed unexpectedly (expected %s)"
- raise self.fail(msg % (nodelist, expected_nodelist))
- self.assertGreaterEqual(
- pymongo.asynchronous.srv_resolver._SrvResolver.get_hosts_and_min_ttl.call_count, # type: ignore
- 1,
- "resolver was never called",
- )
- return True
-
- async def run_scenario(self, dns_response, expect_change):
- self.assertEqual(_have_dnspython(), True)
- if callable(dns_response):
- dns_resolver_response = dns_response
- else:
-
- def dns_resolver_response():
- return dns_response
-
- if expect_change:
- assertion_method = self.assert_nodelist_change
- count_resolver_calls = False
- expected_response = dns_response
- else:
- assertion_method = self.assert_nodelist_nochange
- count_resolver_calls = True
- expected_response = self.BASE_SRV_RESPONSE
-
- # Patch timeouts to ensure short test running times.
- with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
- client = self.simple_client(self.CONNECTION_STRING)
- await client.aconnect()
- await self.assert_nodelist_change(self.BASE_SRV_RESPONSE, client)
- # Patch list of hosts returned by DNS query.
- with SrvPollingKnobs(
- nodelist_callback=dns_resolver_response, count_resolver_calls=count_resolver_calls
- ):
- await assertion_method(expected_response, client)
-
- # Close the client early to avoid affecting the next scenario run.
- await client.close()
-
- async def test_addition(self):
- response = self.BASE_SRV_RESPONSE[:]
- response.append(("localhost.test.build.10gen.cc", 27019))
- await self.run_scenario(response, True)
-
- async def test_removal(self):
- response = self.BASE_SRV_RESPONSE[:]
- response.remove(("localhost.test.build.10gen.cc", 27018))
- await self.run_scenario(response, True)
-
- async def test_replace_one(self):
- response = self.BASE_SRV_RESPONSE[:]
- response.remove(("localhost.test.build.10gen.cc", 27018))
- response.append(("localhost.test.build.10gen.cc", 27019))
- await self.run_scenario(response, True)
-
- async def test_replace_both_with_one(self):
- response = [("localhost.test.build.10gen.cc", 27019)]
- await self.run_scenario(response, True)
-
- async def test_replace_both_with_two(self):
- response = [
- ("localhost.test.build.10gen.cc", 27019),
- ("localhost.test.build.10gen.cc", 27020),
- ]
- await self.run_scenario(response, True)
-
- async def test_dns_failures(self):
- from dns import exception
-
- for exc in (exception.FormError, exception.TooBig, exception.Timeout):
-
- def response_callback(*args):
- raise exc("DNS Failure!")
-
- await self.run_scenario(response_callback, False)
-
- @flaky(reason="PYTHON-5500")
- async def test_dns_failures_logging(self):
- from dns import exception
-
- with self.assertLogs("pymongo.topology", level="DEBUG") as cm:
-
- def response_callback(*args):
- raise exception.Timeout("DNS Failure!")
-
- await self.run_scenario(response_callback, False)
-
- srv_failure_logs = [r for r in cm.records if "SRV monitor check failed" in r.getMessage()]
- self.assertEqual(len(srv_failure_logs), 1)
-
- async def test_dns_record_lookup_empty(self):
- response: list = []
- await self.run_scenario(response, False)
-
- async def _test_recover_from_initial(self, initial_callback):
- # Construct a valid final response callback distinct from base.
- response_final = self.BASE_SRV_RESPONSE[:]
- response_final.pop()
-
- def final_callback():
- return response_final
-
- with SrvPollingKnobs(
- ttl_time=WAIT_TIME,
- min_srv_rescan_interval=WAIT_TIME,
- nodelist_callback=initial_callback,
- count_resolver_calls=True,
- ):
- # Client uses unpatched method to get initial nodelist
- client = self.simple_client(self.CONNECTION_STRING)
- await client.aconnect()
- # Invalid DNS resolver response should not change nodelist.
- await self.assert_nodelist_nochange(self.BASE_SRV_RESPONSE, client)
-
- with SrvPollingKnobs(
- ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME, nodelist_callback=final_callback
- ):
- # Nodelist should reflect new valid DNS resolver response.
- await self.assert_nodelist_change(response_final, client)
-
- @flaky(reason="PYTHON-5315")
- async def test_recover_from_initially_empty_seedlist(self):
- def empty_seedlist():
- return []
-
- await self._test_recover_from_initial(empty_seedlist)
-
- @flaky(reason="PYTHON-5315")
- async def test_recover_from_initially_erroring_seedlist(self):
- def erroring_seedlist():
- raise ConfigurationError
-
- await self._test_recover_from_initial(erroring_seedlist)
-
- async def test_10_all_dns_selected(self):
- response = [
- ("localhost.test.build.10gen.cc", 27017),
- ("localhost.test.build.10gen.cc", 27019),
- ("localhost.test.build.10gen.cc", 27020),
- ]
-
- def nodelist_callback():
- return response
-
- with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
- client = self.simple_client(self.CONNECTION_STRING, srvMaxHosts=0)
- await client.aconnect()
- with SrvPollingKnobs(nodelist_callback=nodelist_callback):
- await self.assert_nodelist_change(response, client)
-
- async def test_11_all_dns_selected(self):
- response = [
- ("localhost.test.build.10gen.cc", 27019),
- ("localhost.test.build.10gen.cc", 27020),
- ]
-
- def nodelist_callback():
- return response
-
- with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
- client = self.simple_client(self.CONNECTION_STRING, srvMaxHosts=2)
- await client.aconnect()
- with SrvPollingKnobs(nodelist_callback=nodelist_callback):
- await self.assert_nodelist_change(response, client)
-
- async def test_12_new_dns_randomly_selected(self):
- response = [
- ("localhost.test.build.10gen.cc", 27020),
- ("localhost.test.build.10gen.cc", 27019),
- ("localhost.test.build.10gen.cc", 27017),
- ]
-
- def nodelist_callback():
- return response
-
- with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
- client = self.simple_client(self.CONNECTION_STRING, srvMaxHosts=2)
- await client.aconnect()
- with SrvPollingKnobs(nodelist_callback=nodelist_callback):
- await asyncio.sleep(2 * common.MIN_SRV_RESCAN_INTERVAL)
- final_topology = set(client.topology_description.server_descriptions())
- self.assertIn(("localhost.test.build.10gen.cc", 27017), final_topology)
- self.assertEqual(len(final_topology), 2)
-
- async def test_does_not_flipflop(self):
- with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
- client = self.simple_client(self.CONNECTION_STRING, srvMaxHosts=1)
- await client.aconnect()
- old = set(client.topology_description.server_descriptions())
- await asyncio.sleep(4 * WAIT_TIME)
- new = set(client.topology_description.server_descriptions())
- self.assertSetEqual(old, new)
-
- async def test_srv_service_name(self):
- # Construct a valid final response callback distinct from base.
- response = [
- ("localhost.test.build.10gen.cc.", 27019),
- ("localhost.test.build.10gen.cc.", 27020),
- ]
-
- def nodelist_callback():
- return response
-
- with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
- client = self.simple_client(
- "mongodb+srv://test22.test.build.10gen.cc/?srvServiceName=customname"
- )
- await client.aconnect()
- with SrvPollingKnobs(nodelist_callback=nodelist_callback):
- await self.assert_nodelist_change(response, client)
-
- async def test_srv_waits_to_poll(self):
- modified = [("localhost.test.build.10gen.cc", 27019)]
-
- def resolver_response():
- return modified
-
- with SrvPollingKnobs(
- ttl_time=WAIT_TIME,
- min_srv_rescan_interval=WAIT_TIME,
- nodelist_callback=resolver_response,
- ):
- client = self.simple_client(self.CONNECTION_STRING)
- await client.aconnect()
- with self.assertRaises(AssertionError):
- await self.assert_nodelist_change(modified, client, timeout=WAIT_TIME / 2)
-
- def test_import_dns_resolver(self):
- # Regression test for PYTHON-4407
- import dns.resolver
-
- self.assertTrue(hasattr(dns.resolver, "resolve") or hasattr(dns.resolver, "query"))
-
-
-if __name__ == "__main__":
- unittest.main()
|