Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass :remote_shutdown messages to the backend #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/flame/runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,20 @@ defmodule FLAME.Runner do
end

%{} ->
{:noreply, maybe_backend_handle_info(state, msg)}
{:noreply, maybe_backend_handle_info(msg, state)}
end
end
end

def handle_info({_ref, {:remote_shutdown, reason}}, state) do
{:stop, {:shutdown, reason}, state}
def handle_info({_ref, {:remote_shutdown, reason}} = msg, state) do
{:stop, {:shutdown, reason}, maybe_backend_handle_info(msg, state)}
end

def handle_info(msg, state) do
{:noreply, maybe_backend_handle_info(state, msg)}
{:noreply, maybe_backend_handle_info(msg, state)}
end

defp maybe_backend_handle_info(state, msg) do
defp maybe_backend_handle_info(msg, state) do
%Runner{backend: backend} = state.runner

if function_exported?(backend, :handle_info, 2) do
Expand Down
4 changes: 4 additions & 0 deletions test/runner_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ defmodule FLAME.RunnerTest do
test "with time" do
timeout = 500
{:ok, runner} = mock_successful_runner(1, idle_shutdown_after: timeout)
expect(MockBackend, :handle_info, fn {_ref, {:remote_shutdown, :idle}}, state -> {:noreply, state} end)

Process.unlink(runner)
Process.monitor(runner)
Expand All @@ -228,6 +229,8 @@ defmodule FLAME.RunnerTest do
assert_receive {:DOWN, _ref, :process, ^runner, _}

{:ok, runner} = mock_successful_runner(2, idle_shutdown_after: timeout)
expect(MockBackend, :handle_info, fn {_ref, {:remote_shutdown, :idle}}, state -> {:noreply, state} end)

Process.unlink(runner)
Process.monitor(runner)
assert Runner.remote_boot(runner, nil) == :ok
Expand All @@ -241,6 +244,7 @@ defmodule FLAME.RunnerTest do
timeout = 500
idle_after = {timeout, fn -> Agent.get(agent, & &1) end}
{:ok, runner} = mock_successful_runner(1, idle_shutdown_after: idle_after)
expect(MockBackend, :handle_info, fn {_ref, {:remote_shutdown, :idle}}, state -> {:noreply, state} end)

Process.unlink(runner)
Process.monitor(runner)
Expand Down