Don't warn on module redefinition (#52)

This commit is contained in:
Jonatan Kłosko 2021-02-22 15:18:37 +01:00 committed by GitHub
parent dc1930634f
commit 207f168239
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View file

@ -93,11 +93,22 @@ defmodule LiveBook.Runtime.ErlDist.Manager do
Process.send_after(self(), :check_owner, @await_owner_timeout)
{:ok, %{owner: nil, evaluators: %{}}}
# Set `ignore_module_conflict` only for the Manager lifetime.
initial_ignore_module_conflict = Code.compiler_options()[:ignore_module_conflict]
Code.compiler_options(ignore_module_conflict: true)
{:ok,
%{
owner: nil,
evaluators: %{},
initial_ignore_module_conflict: initial_ignore_module_conflict
}}
end
@impl true
def terminate(_reason, _state) do
def terminate(_reason, state) do
Code.compiler_options(ignore_module_conflict: state.initial_ignore_module_conflict)
ErlDist.unload_required_modules()
:ok

View file

@ -38,5 +38,23 @@ defmodule LiveBook.Runtime.ErlDist.ManagerTest do
Manager.stop(node())
end
test "prevents from module redefinition warning being printed to standard error" do
Manager.start()
Manager.set_owner(node(), self())
stderr =
ExUnit.CaptureIO.capture_io(:stderr, fn ->
Manager.evaluate_code(node(), "defmodule Foo do end", :container1, :evaluation1)
Manager.evaluate_code(node(), "defmodule Foo do end", :container1, :evaluation2)
assert_receive {:evaluation_response, :evaluation1, _}
assert_receive {:evaluation_response, :evaluation2, _}
end)
assert stderr == ""
Manager.stop(node())
end
end
end