mirror of
				https://github.com/livebook-dev/livebook.git
				synced 2025-10-25 21:06:08 +08:00 
			
		
		
		
	Don't track :rand and :random keys in process dictionary (#1599)
This commit is contained in:
		
							parent
							
								
									3e11023925
								
							
						
					
					
						commit
						82d748a1ff
					
				
					 2 changed files with 23 additions and 1 deletions
				
			
		|  | @ -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, | ||||
|  |  | |||
|  | @ -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, []) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue