From 2399395bfd1d9cdc5e392848a2a071e7c015d941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Thu, 1 Jun 2023 13:49:09 +0200 Subject: [PATCH] Improve tests --- .../runtime/erl_dist/runtime_server_test.exs | 10 ++-- test/livebook/runtime/evaluator_test.exs | 47 +++++++------------ test/livebook_web/live/app_live_test.exs | 1 + 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/test/livebook/runtime/erl_dist/runtime_server_test.exs b/test/livebook/runtime/erl_dist/runtime_server_test.exs index c576aa5bd..4a82070b8 100644 --- a/test/livebook/runtime/erl_dist/runtime_server_test.exs +++ b/test/livebook/runtime/erl_dist/runtime_server_test.exs @@ -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 diff --git a/test/livebook/runtime/evaluator_test.exs b/test/livebook/runtime/evaluator_test.exs index 54167e2c1..ca8f161ff 100644 --- a/test/livebook/runtime/evaluator_test.exs +++ b/test/livebook/runtime/evaluator_test.exs @@ -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 diff --git a/test/livebook_web/live/app_live_test.exs b/test/livebook_web/live/app_live_test.exs index d534fdfc9..4b6be821a 100644 --- a/test/livebook_web/live/app_live_test.exs +++ b/test/livebook_web/live/app_live_test.exs @@ -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)