Add test for standalone Mix runtime (#184)

This commit is contained in:
Jonatan Kłosko 2021-04-14 20:12:14 +02:00 committed by GitHub
parent a3c55a801d
commit d48ae131e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 0 deletions

View file

@ -0,0 +1,43 @@
defmodule Livebook.Runtime.MixStandaloneTest do
use ExUnit.Case, async: true
alias Livebook.Runtime
test "integration" do
# Start node initialization
project_path = Path.expand("../../support/project", __DIR__)
emitter = Livebook.Utils.Emitter.new(self())
Runtime.MixStandalone.init_async(project_path, emitter)
ref = emitter.ref
# Wait for the Mix setup to finish and for node initialization
assert_receive {:emitter, ^ref, {:output, "Running mix deps.get...\n"}}, 5_000
assert_receive {:emitter, ^ref, {:ok, runtime}}, 5_000
Runtime.connect(runtime)
%{node: node} = runtime
# Make sure the node is running.
Node.monitor(node, true)
assert :pong = Node.ping(node)
# Ensure the initialization works
assert evaluator_module_loaded?(node)
assert manager_started?(node)
# Ensure modules from the Mix project are available
assert :rpc.call(node, Project, :hello, []) == "hello"
# Disconnecting should also terminate the node
Runtime.disconnect(runtime)
assert_receive {:nodedown, ^node}
end
defp evaluator_module_loaded?(node) do
:rpc.call(node, :code, :is_loaded, [Livebook.Evaluator]) != false
end
defp manager_started?(node) do
:rpc.call(node, Process, :whereis, [Livebook.Runtime.ErlDist.Manager]) != nil
end
end

1
test/support/project/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/_build/

View file

@ -0,0 +1,5 @@
defmodule Project do
@moduledoc false
def hello, do: "hello"
end

View file

@ -0,0 +1,19 @@
defmodule Project.MixProject do
use Mix.Project
def project do
[
app: :project,
version: "0.1.0",
elixir: "~> 1.11",
start_permanent: Mix.env() == :prod,
deps: []
]
end
def application do
[
extra_applications: [:logger]
]
end
end