Don't track :rand and :random keys in process dictionary (#1599)

This commit is contained in:
Jonatan Kłosko 2022-12-22 11:38:43 +01:00 committed by GitHub
parent 3e11023925
commit 82d748a1ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View file

@ -293,7 +293,7 @@ defmodule Livebook.Runtime.Evaluator do
Process.put(@ebin_path_key, ebin_path)
ignored_pdict_keys = Process.get_keys() |> MapSet.new()
ignored_pdict_keys = MapSet.new([:rand_seed, :random_seed] ++ Process.get_keys())
state = %{
evaluator_ref: evaluator_ref,

View file

@ -96,6 +96,28 @@ defmodule Livebook.Runtime.EvaluatorTest do
assert_receive {:runtime_evaluation_response, :code_3, {:ok, 2}, metadata()}
end
test "keeps :rand state intact in process dictionary", %{evaluator: evaluator} do
Evaluator.evaluate_code(evaluator, ":rand.seed(:default, 0)", :code_1, [])
assert_receive {:runtime_evaluation_response, :code_1, _, metadata()}
Evaluator.evaluate_code(evaluator, ":rand.uniform()", :code_2, [])
assert_receive {:runtime_evaluation_response, :code_2, {:ok, number1}, metadata()}
Evaluator.evaluate_code(evaluator, ":rand.uniform()", :code_2, [])
assert_receive {:runtime_evaluation_response, :code_2, {:ok, number2}, metadata()}
assert number1 != number2
Evaluator.evaluate_code(evaluator, ":rand.seed(:default, 0)", :code_1, [])
assert_receive {:runtime_evaluation_response, :code_1, _, metadata()}
Evaluator.evaluate_code(evaluator, ":rand.uniform()", :code_2, [])
assert_receive {:runtime_evaluation_response, :code_2, {:ok, ^number1}, metadata()}
Evaluator.evaluate_code(evaluator, ":rand.uniform()", :code_2, [])
assert_receive {:runtime_evaluation_response, :code_2, {:ok, ^number2}, metadata()}
end
test "captures standard output and sends it to the caller", %{evaluator: evaluator} do
Evaluator.evaluate_code(evaluator, ~s{IO.puts("hey")}, :code_1, [])