コード例 #1
0
async def test_first_success_strategy_returns_first_completed_success_response():
    rs = jsonrpc.async_client.RequestWithBackups(backups=["backup"])
    client = AsyncClient("primary", rs=rs)

    client._send_http_request = gen_metadata_response(client, snap="primary")
    metadata = await client.get_metadata()
    assert metadata.script_hash_allow_list == ["backup"]

    client._send_http_request = gen_metadata_response(client, snap="backup")
    metadata = await client.get_metadata()
    assert metadata.script_hash_allow_list == ["primary"]
コード例 #2
0
async def test_fallback_to_second_if_first_failed():
    rs = jsonrpc.async_client.RequestWithBackups(backups=["backup"])
    client = AsyncClient("primary", rs=rs)

    # primary will fail immediately, backup is slow but success
    client._send_http_request = gen_metadata_response(client, fail="primary", snap="backup")
    metadata = await client.get_metadata()
    assert metadata.script_hash_allow_list == ["backup"]
コード例 #3
0
async def test_fallback_to_backups_when_primary_failed():
    client = AsyncClient(
        "primary",
        rs=jsonrpc.async_client.RequestWithBackups(backups=["backup"], fallback=True),
    )
    client._send_http_request = gen_metadata_response(client, fail="primary")
    for _ in range(10):
        metadata = await client.get_metadata()
        assert metadata.script_hash_allow_list == ["backup"]
コード例 #4
0
async def test_fallback_strategy_always_returns_primary_response_if_it_successes():
    client = AsyncClient(
        "primary",
        rs=jsonrpc.async_client.RequestWithBackups(backups=["backup"], fallback=True),
    )
    client._send_http_request = gen_metadata_response(client)
    for _ in range(10):
        metadata = await client.get_metadata()
        assert metadata.script_hash_allow_list == ["primary"]