|
|
@ -26,28 +26,35 @@ defmodule EthereumJSONRPC.RequestCoordinatorTest do |
|
|
|
describe "perform/4" do |
|
|
|
describe "perform/4" do |
|
|
|
test "forwards result whenever a request doesn't timeout", %{timeout_table: timeout_table} do |
|
|
|
test "forwards result whenever a request doesn't timeout", %{timeout_table: timeout_table} do |
|
|
|
expect(EthereumJSONRPC.Mox, :json_rpc, fn _, _ -> {:ok, %{}} end) |
|
|
|
expect(EthereumJSONRPC.Mox, :json_rpc, fn _, _ -> {:ok, %{}} end) |
|
|
|
assert RollingWindow.count(timeout_table, :throttleable_error_count) == 0 |
|
|
|
assert RollingWindow.count(timeout_table, :throttleable_error_count_eth_call) == 0 |
|
|
|
assert {:ok, %{}} == RequestCoordinator.perform(%{}, EthereumJSONRPC.Mox, [], :timer.minutes(60)) |
|
|
|
|
|
|
|
assert RollingWindow.count(timeout_table, :throttleable_error_count) == 0 |
|
|
|
assert {:ok, %{}} == |
|
|
|
|
|
|
|
RequestCoordinator.perform(%{method: "eth_call"}, EthereumJSONRPC.Mox, [], :timer.minutes(60)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert RollingWindow.count(timeout_table, :throttleable_error_count_eth_call) == 0 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "increments counter on certain errors", %{timeout_table: timeout_table} do |
|
|
|
test "increments counter on certain errors", %{timeout_table: timeout_table} do |
|
|
|
expect(EthereumJSONRPC.Mox, :json_rpc, fn :timeout, _ -> {:error, :timeout} end) |
|
|
|
expect(EthereumJSONRPC.Mox, :json_rpc, fn %{method: "timeout"}, _ -> {:error, :timeout} end) |
|
|
|
expect(EthereumJSONRPC.Mox, :json_rpc, fn :bad_gateway, _ -> {:error, {:bad_gateway, "message"}} end) |
|
|
|
expect(EthereumJSONRPC.Mox, :json_rpc, fn %{method: "bad_gateway"}, _ -> {:error, {:bad_gateway, "message"}} end) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert {:error, :timeout} == |
|
|
|
|
|
|
|
RequestCoordinator.perform(%{method: "timeout"}, EthereumJSONRPC.Mox, [], :timer.minutes(60)) |
|
|
|
|
|
|
|
|
|
|
|
assert {:error, :timeout} == RequestCoordinator.perform(:timeout, EthereumJSONRPC.Mox, [], :timer.minutes(60)) |
|
|
|
assert RollingWindow.count(timeout_table, :throttleable_error_count_timeout) == 1 |
|
|
|
assert RollingWindow.count(timeout_table, :throttleable_error_count) == 1 |
|
|
|
assert RollingWindow.count(timeout_table, :throttleable_error_count_bad_gateway) == 0 |
|
|
|
|
|
|
|
|
|
|
|
assert {:error, {:bad_gateway, "message"}} == |
|
|
|
assert {:error, {:bad_gateway, "message"}} == |
|
|
|
RequestCoordinator.perform(:bad_gateway, EthereumJSONRPC.Mox, [], :timer.minutes(60)) |
|
|
|
RequestCoordinator.perform(%{method: "bad_gateway"}, EthereumJSONRPC.Mox, [], :timer.minutes(60)) |
|
|
|
|
|
|
|
|
|
|
|
assert RollingWindow.count(timeout_table, :throttleable_error_count) == 2 |
|
|
|
assert RollingWindow.count(timeout_table, :throttleable_error_count_timeout) == 1 |
|
|
|
|
|
|
|
assert RollingWindow.count(timeout_table, :throttleable_error_count_bad_gateway) == 1 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "returns timeout error if sleep time will exceed max timeout", %{timeout_table: timeout_table} do |
|
|
|
test "returns timeout error if sleep time will exceed max timeout", %{timeout_table: timeout_table} do |
|
|
|
expect(EthereumJSONRPC.Mox, :json_rpc, 0, fn _, _ -> :ok end) |
|
|
|
expect(EthereumJSONRPC.Mox, :json_rpc, 0, fn _, _ -> :ok end) |
|
|
|
RollingWindow.inc(timeout_table, :throttleable_error_count) |
|
|
|
RollingWindow.inc(timeout_table, :throttleable_error_count_eth_call) |
|
|
|
assert {:error, :timeout} == RequestCoordinator.perform(%{}, EthereumJSONRPC.Mox, [], 1) |
|
|
|
assert {:error, :timeout} == RequestCoordinator.perform(%{method: "eth_call"}, EthereumJSONRPC.Mox, [], 1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "increments throttle_table even when not an error", %{throttle_table: throttle_table} do |
|
|
|
test "increments throttle_table even when not an error", %{throttle_table: throttle_table} do |
|
|
|