From 3b51c26d626eb6129abff2135e77cabd7b57afa1 Mon Sep 17 00:00:00 2001 From: Thomas Miedema Date: Fri, 6 May 2022 14:26:42 +0200 Subject: [PATCH] ValueError: list.remove(x): x not in list There is a bug in `StaticSeedFinder`, which results in the following error when running this test: def mark_failed(self, seed): > self._seeds.remove(seed) E ValueError: list.remove(x): x not in list --- test/discovery_test.py | 58 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/test/discovery_test.py b/test/discovery_test.py index 64cdd1c..64266f6 100644 --- a/test/discovery_test.py +++ b/test/discovery_test.py @@ -35,6 +35,17 @@ ) +class always_fail(DiscoveryRetryPolicy): + def __init__(self): + super().__init__() + + def should_retry(self, _): + return False + + async def wait(self, seed): + pass + + def test_selector_with_one_node(): gossip = [GOOD_NODE] @@ -232,23 +243,50 @@ async def wait(self, seed): assert stats.consecutive_failures == 0 +@pytest.mark.xfail(reason="Bug in StaticSeedFinder", raises=ValueError) @pytest.mark.asyncio -async def test_repeated_discovery_failure_for_static_seed(): +async def test_discovery_failure_on_a_discovered_node(): """ - When gossip fetch fails `maximum_retry_count` times, we should fail with a - DiscoverFailed error. + When gossip fetch fails for a discovered node, we should retry the seed node """ + seed_ip = "1.2.3.4" + discovered_ip = "2.3.4.5" - class always_fail(DiscoveryRetryPolicy): - def __init__(self): - super().__init__() + seed = NodeService(seed_ip, 2113, None) + discovered = NodeService(discovered_ip, 2113, None) - def should_retry(self, _): - return False + gossip = data.make_gossip(discovered_ip) + retry = always_fail() + discoverer = ClusterDiscovery(StaticSeedFinder([seed]), retry, None) + with aioresponses() as mock: + mock.get(f"http://{seed_ip}:2113/gossip", payload=gossip) + mock.get(f"http://{discovered_ip}:2113/gossip", status=500) + mock.get(f"http://{seed_ip}:2113/gossip", payload=gossip) + + assert await discoverer.next_node() == NodeService(discovered_ip, 1113, None) + assert await discoverer.next_node() == NodeService(discovered_ip, 1113, None) + + seed_stats = retry.stats[seed] + + assert seed_stats.attempts == 2 + assert seed_stats.successes == 2 + assert seed_stats.failures == 0 + assert seed_stats.consecutive_failures == 0 + + discovered_stats = retry.stats[discovered] + + assert discovered_stats.attempts == 1 + assert discovered_stats.successes == 0 + assert discovered_stats.failures == 1 + assert discovered_stats.consecutive_failures == 1 - async def wait(self, seed): - pass +@pytest.mark.asyncio +async def test_repeated_discovery_failure_for_static_seed(): + """ + When gossip fetch fails `maximum_retry_count` times, we should fail with a + DiscoverFailed error. + """ seed = NodeService("1.2.3.4", 2113, None) retry = always_fail() gossip = data.make_gossip("2.3.4.5")