mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-10 13:38:09 +08:00
Test remote intellisense on a standalone runtime node (#2638)
This commit is contained in:
parent
e88e5f02c7
commit
130e94eb7f
1 changed files with 42 additions and 34 deletions
|
@ -3,7 +3,6 @@ defmodule Livebook.RemoteIntellisenseTest do
|
||||||
alias Livebook.Intellisense
|
alias Livebook.Intellisense
|
||||||
|
|
||||||
@moduletag :with_epmd
|
@moduletag :with_epmd
|
||||||
@tmp_dir "tmp/test/remote_intellisense"
|
|
||||||
|
|
||||||
# Returns intellisense context resulting from evaluating
|
# Returns intellisense context resulting from evaluating
|
||||||
# the given block of code in a fresh context.
|
# the given block of code in a fresh context.
|
||||||
|
@ -22,43 +21,52 @@ defmodule Livebook.RemoteIntellisenseTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
{:ok, _pid, node} =
|
# We use the standalone runtime to mimic a remote node. Note that
|
||||||
:peer.start(%{
|
# in the past we used :peer.start, but it was often failing on CI
|
||||||
name: :remote_runtime,
|
# (the start was timing out)
|
||||||
args: [~c"-setcookie", Atom.to_charlist(Node.get_cookie())],
|
|
||||||
wait_boot: 30_000
|
{:ok, runtime} = Livebook.Runtime.ElixirStandalone.new() |> Livebook.Runtime.connect()
|
||||||
|
|
||||||
|
parent = self()
|
||||||
|
|
||||||
|
runtime_owner_pid =
|
||||||
|
start_supervised!({
|
||||||
|
Task,
|
||||||
|
fn ->
|
||||||
|
Livebook.Runtime.take_ownership(runtime)
|
||||||
|
|
||||||
|
code =
|
||||||
|
~S'''
|
||||||
|
defmodule RemoteModule do
|
||||||
|
@moduledoc """
|
||||||
|
RemoteModule module docs
|
||||||
|
"""
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Hello doc
|
||||||
|
"""
|
||||||
|
def hello(message) do
|
||||||
|
message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'''
|
||||||
|
|
||||||
|
Livebook.Runtime.evaluate_code(runtime, :elixir, code, {:c1, :e1}, [])
|
||||||
|
|
||||||
|
receive do: ({:runtime_evaluation_response, :e1, _, _} -> :ok)
|
||||||
|
send(parent, :continue)
|
||||||
|
|
||||||
|
Process.sleep(:infinity)
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
{:module, Elixir.RemoteModule, bytecode, _} =
|
receive do: (:continue -> :ok)
|
||||||
defmodule Elixir.RemoteModule do
|
|
||||||
@compile {:autoload, false}
|
|
||||||
@moduledoc """
|
|
||||||
RemoteModule module docs
|
|
||||||
"""
|
|
||||||
|
|
||||||
@doc """
|
on_exit(fn ->
|
||||||
Hello doc
|
Process.exit(runtime_owner_pid, :kill)
|
||||||
"""
|
end)
|
||||||
def hello(message) do
|
|
||||||
message
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
false = Code.ensure_loaded?(RemoteModule)
|
[node: runtime.node]
|
||||||
|
|
||||||
File.rm_rf!(@tmp_dir)
|
|
||||||
File.mkdir_p!(@tmp_dir)
|
|
||||||
File.write!("#{@tmp_dir}/Elixir.RemoteModule.beam", bytecode)
|
|
||||||
|
|
||||||
elixir_path = Path.join(:code.lib_dir(:elixir), "ebin")
|
|
||||||
|
|
||||||
:ok = :erpc.call(node, :code, :add_paths, [[~c"#{@tmp_dir}", ~c"#{elixir_path}"]])
|
|
||||||
{:ok, _} = :erpc.call(node, :application, :ensure_all_started, [:elixir])
|
|
||||||
{:module, RemoteModule} = :erpc.call(node, :code, :load_file, [RemoteModule])
|
|
||||||
:loaded = :erpc.call(node, :code, :module_status, [RemoteModule])
|
|
||||||
:ok = :erpc.call(node, :application, :load, [:mnesia])
|
|
||||||
|
|
||||||
[node: node]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "intellisense completion for remote nodes" do
|
describe "intellisense completion for remote nodes" do
|
||||||
|
|
Loading…
Add table
Reference in a new issue