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

Method test_heartbeat_frequency_ms

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

Source from the content-addressed store, hash-verified

1637 )
1638
1639 def test_heartbeat_frequency_ms(self):
1640 class HeartbeatStartedListener(ServerHeartbeatListener):
1641 def __init__(self):
1642 self.results = []
1643
1644 def started(self, event):
1645 self.results.append(event)
1646
1647 def succeeded(self, event):
1648 pass
1649
1650 def failed(self, event):
1651 pass
1652
1653 old_init = ServerHeartbeatStartedEvent.__init__
1654 heartbeat_times = []
1655
1656 def init(self, *args):
1657 old_init(self, *args)
1658 heartbeat_times.append(time.time())
1659
1660 try:
1661 ServerHeartbeatStartedEvent.__init__ = init # type: ignore
1662 listener = HeartbeatStartedListener()
1663 uri = "mongodb://%s:%d/?heartbeatFrequencyMS=500" % (
1664 client_context.host,
1665 client_context.port,
1666 )
1667 self.single_client(uri, event_listeners=[listener])
1668 wait_until(
1669 lambda: len(listener.results) >= 2, "record two ServerHeartbeatStartedEvents"
1670 )
1671
1672 # Default heartbeatFrequencyMS is 10 sec. Check the interval was
1673 # closer to 0.5 sec with heartbeatFrequencyMS configured.
1674 self.assertAlmostEqual(heartbeat_times[1] - heartbeat_times[0], 0.5, delta=2)
1675
1676 finally:
1677 ServerHeartbeatStartedEvent.__init__ = old_init # type: ignore
1678
1679 def test_small_heartbeat_frequency_ms(self):
1680 uri = "mongodb://example/?heartbeatFrequencyMS=499"

Callers

nothing calls this directly

Calls 3

wait_untilFunction · 0.90
single_clientMethod · 0.80

Tested by

no test coverage detected