async def test_cluster_discovery_mark_failed(): """ ClusterDiscovery should just pass the mark_failed call to the seed source. """ class spy_seed_finder(List): def mark_failed(self, node): self.append(node) node = NodeService("2.3.4.5", 1234, None) finder = spy_seed_finder() discoverer = ClusterDiscovery(finder, None, None, None) discoverer.mark_failed(node) assert finder == [node]
async def test_repeated_discovery_failure_for_static_seed(): """ When gossip fetch fails `maximum_retry_count` times, we should fail with a DiscoverFailed error. """ class always_fail(DiscoveryRetryPolicy): def __init__(self): super().__init__() def should_retry(self, _): return False async def wait(self, seed): pass seed = NodeService("1.2.3.4", 2113, None) retry = always_fail() gossip = data.make_gossip("2.3.4.5") with aioresponses() as mock: successful_discoverer = ClusterDiscovery(StaticSeedFinder([seed]), retry, None) mock.get("http://1.2.3.4:2113/gossip", status=500) mock.get("http://1.2.3.4:2113/gossip", payload=gossip) with pytest.raises(DiscoveryFailed): assert await successful_discoverer.next_node() == NodeService( "2.3.4.5", 1113, None) stats = retry.stats[seed] assert stats.attempts == 1 assert stats.successes == 0 assert stats.failures == 1 assert stats.consecutive_failures == 1
async def test_discovery_failure_for_static_seed(): """ When gossip fetch fails for a static seed, we should call the retry thing """ class always_succeed(DiscoveryRetryPolicy): def __init__(self): super().__init__() self.stats = Stats() def should_retry(self, _): return True async def wait(self, seed): pass seed = NodeService("1.2.3.4", 2113, None) gossip = data.make_gossip("2.3.4.5") retry = always_succeed() with aioresponses() as mock: successful_discoverer = ClusterDiscovery(StaticSeedFinder([seed]), retry, None) mock.get("http://1.2.3.4:2113/gossip", status=500) mock.get("http://1.2.3.4:2113/gossip", payload=gossip) assert await successful_discoverer.next_node() == NodeService( "2.3.4.5", 1113, None) stats = retry.stats[seed] assert stats.attempts == 2 assert stats.successes == 1 assert stats.failures == 1 assert stats.consecutive_failures == 0