Skip to content

Commit

Permalink
wait till peer_count is equal to 1 (nodes are connected after reorg)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 committed Jul 4, 2020
1 parent 42cb393 commit 32e2394
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
23 changes: 23 additions & 0 deletions priv/cabbage/apps/itest/lib/poller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@ defmodule Itest.Poller do
def wait_on_receipt_confirmed(receipt_hash),
do: wait_on_receipt_status(receipt_hash, "0x1", @retry_count)

@doc """
Waits until the node has the required peers nubmer.
"""
def wait_until_peer_count(peer_count) do
case Ethereumex.HttpClient.net_peer_count() do
{:ok, "0x" <> number_hex} ->
{count, ""} = Integer.parse(number_hex, 16)

IO.inspect(count)

if count >= peer_count do
:ok
else
Process.sleep(2_000)
wait_until_peer_count(peer_count)
end

_other ->
Process.sleep(2_000)
wait_until_peer_count(peer_count)
end
end

@doc """
API:: Pull until the utxo is not found for the address.
"""
Expand Down
10 changes: 3 additions & 7 deletions priv/cabbage/apps/itest/lib/reorg.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ defmodule Itest.Reorg do

@node1 "geth-1"
@node2 "geth-2"
@pause_seconds 100

@rpc_nodes ["http://localhost:9000", "http://localhost:9001"]

Expand All @@ -34,21 +33,18 @@ defmodule Itest.Reorg do

func.()

Process.sleep(@pause_seconds * 1000)
Process.sleep(20 * 1000)

pause_container!(@node2)
unpause_container!(@node1)

response = func.()

# the second sleep is shorter so the number of generated blocks is smaller
Process.sleep(floor(@pause_seconds / 5) * 1000)

unpause_container!(@node2)
unpause_container!(@node1)

# wait for reorg
Process.sleep(30 * 1000)
Poller.wait_until_peer_count(1)
Process.sleep(30_000)

response
else
Expand Down

0 comments on commit 32e2394

Please sign in to comment.