Skip to content

Commit

Permalink
Merge pull request #3 from wowica/refactor-test
Browse files Browse the repository at this point in the history
Simplify test
  • Loading branch information
caike authored Jan 2, 2024
2 parents ed2cdf2 + 63af832 commit 5f6c4cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lib/xogmios/client_example_b.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ defmodule Xogmios.ClientExampleB do
@impl true
def handle_block(block, %{counter: counter} = state) when counter > 1 do
Logger.info("#{__MODULE__} handle_block #{block["height"]}")

new_state = Map.merge(state, %{counter: counter - 1})
{:ok, :next_block, new_state}
end

@impl true
def handle_block(block, state) do
Logger.info("#{__MODULE__} final handle_block #{block["height"]}")

{:ok, :close, state}
end
end
19 changes: 7 additions & 12 deletions test/xogmios_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ defmodule XogmiosTest do
send(state.target, :handle_block)
{:ok, :close, state}
end

@impl true
def terminate(_reason, state) do
send(state.target, :terminate)
:ok
end
end

test "receives handle block" do
Expand All @@ -44,17 +50,6 @@ defmodule XogmiosTest do
Process.sleep(1000)
refute Process.alive?(pid)
assert GenServer.whereis(DummyClient) == nil
end

test "restarts process when restart: :permanent" do
pid =
start_supervised!({DummyClient, url: @ws_url, target: self(), restart: :permanent})

whereis_pid = GenServer.whereis(DummyClient)
assert whereis_pid == pid
assert is_pid(pid)
Process.sleep(1000)
assert GenServer.whereis(DummyClient) != nil
assert GenServer.whereis(DummyClient) != whereis_pid
assert_receive :terminate
end
end

0 comments on commit 5f6c4cd

Please sign in to comment.