Merge pull request #1123 from poanetwork/frg-increase-token-balance-fetcher-timeout

Increase the timeout to 15s in Indexer.TokenBalances
pull/1126/head
Andrew Cravenho 6 years ago committed by GitHub
commit 6d9ba54cb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      apps/indexer/lib/indexer/token_balances.ex
  2. 17
      apps/indexer/test/indexer/token_balances_test.exs

@ -9,6 +9,9 @@ defmodule Indexer.TokenBalances do
alias Explorer.Token.BalanceReader
alias Indexer.TokenBalance
# The timeout used for each process opened by Task.async_stream/3. Default 15s.
@task_timeout 15000
@doc """
Fetches TokenBalances from specific Addresses and Blocks in the Blockchain
@ -26,12 +29,14 @@ defmodule Indexer.TokenBalances do
"""
def fetch_token_balances_from_blockchain([]), do: {:ok, []}
def fetch_token_balances_from_blockchain(token_balances) do
def fetch_token_balances_from_blockchain(token_balances, opts \\ []) do
Logger.debug(fn -> "fetching #{Enum.count(token_balances)} token balances" end)
task_timeout = Keyword.get(opts, :timeout, @task_timeout)
requested_token_balances =
token_balances
|> Task.async_stream(&fetch_token_balance/1, on_timeout: :kill_task)
|> Task.async_stream(&fetch_token_balance/1, timeout: task_timeout, on_timeout: :kill_task)
|> Stream.map(&format_task_results/1)
|> Enum.filter(&ignore_killed_task/1)

@ -84,9 +84,9 @@ defmodule Indexer.TokenBalancesTest do
]
get_balance_from_blockchain()
get_balance_from_blockchain_with_timeout()
get_balance_from_blockchain_with_timeout(200)
{:ok, result} = TokenBalances.fetch_token_balances_from_blockchain(token_balance_params)
{:ok, result} = TokenBalances.fetch_token_balances_from_blockchain(token_balance_params, timeout: 100)
assert length(result) == 1
end
@ -190,12 +190,21 @@ defmodule Indexer.TokenBalancesTest do
)
end
defp get_balance_from_blockchain_with_timeout() do
defp get_balance_from_blockchain_with_timeout(timeout) do
expect(
EthereumJSONRPC.Mox,
:json_rpc,
fn [%{id: _, method: _, params: [%{data: _, to: _}, _]}], _options ->
:timer.sleep(5001)
:timer.sleep(timeout)
{:ok,
[
%{
id: "balanceOf",
jsonrpc: "2.0",
result: "0x00000000000000000000000000000000000000000000d3c21bcecceda1000000"
}
]}
end
)
end

Loading…
Cancel
Save