Improve tests

This commit is contained in:
Jonatan Kłosko 2023-06-01 13:49:09 +02:00
parent 8f71ad700b
commit 2399395bfd
3 changed files with 24 additions and 34 deletions

View file

@ -1,5 +1,5 @@
defmodule Livebook.Runtime.ErlDist.RuntimeServerTest do
use ExUnit.Case, async: false
use ExUnit.Case, async: true
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}}
end)
assert stderr == ""
refute stderr =~ "redefining module Foo"
end
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
@tag capture_log: true

View file

@ -57,12 +57,10 @@ defmodule Livebook.Runtime.EvaluatorTest do
Evaluator.evaluate_code(evaluator, "x = 1", :code_1, [])
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,
{:error, _kind, %CompileError{}, _stacktrace}, metadata()}
end)
assert_receive {:runtime_evaluation_response, :code_2,
{:error, _kind, %CompileError{}, _stacktrace}, metadata()}
end
test "given parent refs sees previous evaluation context", %{evaluator: evaluator} do
@ -227,21 +225,19 @@ defmodule Livebook.Runtime.EvaluatorTest do
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 = [
{Livebook.Runtime.EvaluatorTest.Stacktrace.Math, :bad_math, 0,
[file: ~c"nofile", line: 3]},
{Livebook.Runtime.EvaluatorTest.Stacktrace.Cat, :meow, 0, [file: ~c"nofile", line: 10]},
{:elixir_eval, :__FILE__, 1, [file: ~c"nofile", line: 15]}
]
expected_stacktrace = [
{Livebook.Runtime.EvaluatorTest.Stacktrace.Math, :bad_math, 0,
[file: ~c"nofile", line: 3]},
{Livebook.Runtime.EvaluatorTest.Stacktrace.Cat, :meow, 0, [file: ~c"nofile", line: 10]},
{:elixir_eval, :__FILE__, 1, [file: ~c"nofile", line: 15]}
]
# Note: evaluating module definitions is relatively slow, so we use a higher wait timeout.
assert_receive {:runtime_evaluation_response, :code_1,
{:error, _kind, _error, ^expected_stacktrace}, metadata()},
2_000
end)
# Note: evaluating module definitions is relatively slow, so we use a higher wait timeout.
assert_receive {:runtime_evaluation_response, :code_1,
{:error, _kind, _error, ^expected_stacktrace}, metadata()},
2_000
end
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)
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,
{:error, _kind, %CompileError{}, _stacktrace}, metadata()}
end)
assert_receive {:runtime_evaluation_response, :code_2,
{:error, _kind, %CompileError{}, _stacktrace}, metadata()}
end
test "kills widgets that no evaluation points to", %{evaluator: evaluator} do
@ -1091,13 +1085,6 @@ defmodule Livebook.Runtime.EvaluatorTest do
# 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
# a pointer for it and adds monitoring, then returns widget
# pid from the evaluation

View file

@ -64,6 +64,7 @@ defmodule LivebookWeb.AppLiveTest do
sessions: [%{app_status: %{lifecycle: :deactivated}}, _, _]
}}
assert render(view) =~ ~p"/apps/#{slug}/#{session_id1}"
refute render(view) =~ ~p"/apps/#{slug}/#{session_id3}"
App.close(app_pid)