Example #1
0
async def test_discovery_with_a_static_seed():
    """
    When we create a discoverer with a static seed address we
    should query that address for gossip and then select the
    best node from the result.

    On a subsequent call, we should use the previously discovered
    nodes to find gossip.
    """

    seed_ip = "10.10.10.10"
    first_node_ip = "172.31.0.1"
    second_node_ip = "192.168.168.192"

    first_gossip = data.make_gossip(first_node_ip)
    second_gossip = data.make_gossip(second_node_ip)

    discoverer = get_discoverer(None, None, seed_ip, 2113)
    with aioresponses() as mock:
        mock.get(f"http://{seed_ip}:2113/gossip",
                 status=200,
                 payload=first_gossip)

        mock.get(f"http://{first_node_ip}:2113/gossip",
                 status=200,
                 payload=second_gossip)

        assert await discoverer.next_node() == NodeService(
            first_node_ip, 1113, None)
        assert await discoverer.next_node() == NodeService(
            second_node_ip, 1113, None)
        assert discoverer.retry_policy.retries_per_node == 3
async def test_discovery_with_a_single_node():
    """
    When we create a discoverer with a single address and no
    discovery information, we should receive an async generator
    that returns the same node over and over.
    """
    discoverer = get_discoverer("localhost", 1113, None, None)

    for i in range(0, 5):
        assert await discoverer.discover() == NodeService("localhost", 1113, None)
async def test_prefer_master():
    """
    If we ask the discoverer to prefer_master it should return a master node
    before returning a replica.
    """

    discoverer = get_discoverer(None, None, "10.0.0.1", 2113, prefer_master)
    gossip = data.make_gossip("10.0.0.1", "10.0.0.2")
    with aioresponses() as mock:
        mock.get("http://10.0.0.1:2113/gossip", payload=gossip)

        assert await discoverer.next_node() == NodeService("10.0.0.1", 1113, None)