mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-11-12 07:01:40 +08:00
Improve tests
This commit is contained in:
parent
8f71ad700b
commit
2399395bfd
3 changed files with 24 additions and 34 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule Livebook.Runtime.ErlDist.RuntimeServerTest do
|
defmodule Livebook.Runtime.ErlDist.RuntimeServerTest do
|
||||||
use ExUnit.Case, async: false
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
alias Livebook.Runtime.ErlDist.{NodeManager, RuntimeServer}
|
alias Livebook.Runtime.ErlDist.{NodeManager, RuntimeServer}
|
||||||
|
|
||||||
|
|
@ -51,13 +51,15 @@ defmodule Livebook.Runtime.ErlDist.RuntimeServerTest do
|
||||||
assert_receive {:runtime_evaluation_response, :e2, _, %{evaluation_time_ms: _time_ms}}
|
assert_receive {:runtime_evaluation_response, :e2, _, %{evaluation_time_ms: _time_ms}}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
assert stderr == ""
|
refute stderr =~ "redefining module Foo"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "proxies evaluation stderr to evaluation stdout", %{pid: pid} do
|
test "proxies evaluation stderr to evaluation stdout", %{pid: pid} do
|
||||||
RuntimeServer.evaluate_code(pid, ~s{IO.puts(:stderr, "error")}, {:c1, :e1}, [])
|
RuntimeServer.evaluate_code(pid, ~s{IO.puts(:stderr, "error to stdout")}, {:c1, :e1}, [])
|
||||||
|
|
||||||
assert_receive {:runtime_evaluation_output, :e1, {:stdout, "error\n"}}
|
assert_receive {:runtime_evaluation_output, :e1, {:stdout, output}}
|
||||||
|
|
||||||
|
assert output =~ "error to stdout\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
@tag capture_log: true
|
@tag capture_log: true
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,10 @@ defmodule Livebook.Runtime.EvaluatorTest do
|
||||||
Evaluator.evaluate_code(evaluator, "x = 1", :code_1, [])
|
Evaluator.evaluate_code(evaluator, "x = 1", :code_1, [])
|
||||||
assert_receive {:runtime_evaluation_response, :code_1, _, metadata()}
|
assert_receive {:runtime_evaluation_response, :code_1, _, metadata()}
|
||||||
|
|
||||||
ignore_warnings(fn ->
|
|
||||||
Evaluator.evaluate_code(evaluator, "x", :code_2, [])
|
Evaluator.evaluate_code(evaluator, "x", :code_2, [])
|
||||||
|
|
||||||
assert_receive {:runtime_evaluation_response, :code_2,
|
assert_receive {:runtime_evaluation_response, :code_2,
|
||||||
{:error, _kind, %CompileError{}, _stacktrace}, metadata()}
|
{:error, _kind, %CompileError{}, _stacktrace}, metadata()}
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "given parent refs sees previous evaluation context", %{evaluator: evaluator} do
|
test "given parent refs sees previous evaluation context", %{evaluator: evaluator} do
|
||||||
|
|
@ -227,7 +225,6 @@ defmodule Livebook.Runtime.EvaluatorTest do
|
||||||
Livebook.Runtime.EvaluatorTest.Stacktrace.Cat.meow()
|
Livebook.Runtime.EvaluatorTest.Stacktrace.Cat.meow()
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ignore_warnings(fn ->
|
|
||||||
Evaluator.evaluate_code(evaluator, code, :code_1, [])
|
Evaluator.evaluate_code(evaluator, code, :code_1, [])
|
||||||
|
|
||||||
expected_stacktrace = [
|
expected_stacktrace = [
|
||||||
|
|
@ -241,7 +238,6 @@ defmodule Livebook.Runtime.EvaluatorTest do
|
||||||
assert_receive {:runtime_evaluation_response, :code_1,
|
assert_receive {:runtime_evaluation_response, :code_1,
|
||||||
{:error, _kind, _error, ^expected_stacktrace}, metadata()},
|
{:error, _kind, _error, ^expected_stacktrace}, metadata()},
|
||||||
2_000
|
2_000
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "in case of an error uses empty evaluation context as the resulting context",
|
test "in case of an error uses empty evaluation context as the resulting context",
|
||||||
|
|
@ -1005,12 +1001,10 @@ defmodule Livebook.Runtime.EvaluatorTest do
|
||||||
|
|
||||||
Evaluator.forget_evaluation(evaluator, :code_1)
|
Evaluator.forget_evaluation(evaluator, :code_1)
|
||||||
|
|
||||||
ignore_warnings(fn ->
|
|
||||||
Evaluator.evaluate_code(evaluator, "x", :code_2, [:code_1])
|
Evaluator.evaluate_code(evaluator, "x", :code_2, [:code_1])
|
||||||
|
|
||||||
assert_receive {:runtime_evaluation_response, :code_2,
|
assert_receive {:runtime_evaluation_response, :code_2,
|
||||||
{:error, _kind, %CompileError{}, _stacktrace}, metadata()}
|
{:error, _kind, %CompileError{}, _stacktrace}, metadata()}
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "kills widgets that no evaluation points to", %{evaluator: evaluator} do
|
test "kills widgets that no evaluation points to", %{evaluator: evaluator} do
|
||||||
|
|
@ -1091,13 +1085,6 @@ defmodule Livebook.Runtime.EvaluatorTest do
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
|
|
||||||
# Some of the code passed to Evaluator above is expected
|
|
||||||
# to produce compilation warnings, so we ignore them.
|
|
||||||
defp ignore_warnings(fun) do
|
|
||||||
ExUnit.CaptureIO.capture_io(:stderr, fun)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a code that spawns a widget process, registers
|
# Returns a code that spawns a widget process, registers
|
||||||
# a pointer for it and adds monitoring, then returns widget
|
# a pointer for it and adds monitoring, then returns widget
|
||||||
# pid from the evaluation
|
# pid from the evaluation
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ defmodule LivebookWeb.AppLiveTest do
|
||||||
sessions: [%{app_status: %{lifecycle: :deactivated}}, _, _]
|
sessions: [%{app_status: %{lifecycle: :deactivated}}, _, _]
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
assert render(view) =~ ~p"/apps/#{slug}/#{session_id1}"
|
||||||
refute render(view) =~ ~p"/apps/#{slug}/#{session_id3}"
|
refute render(view) =~ ~p"/apps/#{slug}/#{session_id3}"
|
||||||
|
|
||||||
App.close(app_pid)
|
App.close(app_pid)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue