mirror of
				https://github.com/livebook-dev/livebook.git
				synced 2025-11-04 10:26:08 +08:00 
			
		
		
		
	Add test for standalone Mix runtime (#184)
This commit is contained in:
		
							parent
							
								
									a3c55a801d
								
							
						
					
					
						commit
						d48ae131e6
					
				
					 4 changed files with 68 additions and 0 deletions
				
			
		
							
								
								
									
										43
									
								
								test/livebook/runtime/mix_standalone_test.exs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								test/livebook/runtime/mix_standalone_test.exs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,43 @@
 | 
			
		|||
defmodule Livebook.Runtime.MixStandaloneTest do
 | 
			
		||||
  use ExUnit.Case, async: true
 | 
			
		||||
 | 
			
		||||
  alias Livebook.Runtime
 | 
			
		||||
 | 
			
		||||
  test "integration" do
 | 
			
		||||
    # Start node initialization
 | 
			
		||||
    project_path = Path.expand("../../support/project", __DIR__)
 | 
			
		||||
    emitter = Livebook.Utils.Emitter.new(self())
 | 
			
		||||
    Runtime.MixStandalone.init_async(project_path, emitter)
 | 
			
		||||
 | 
			
		||||
    ref = emitter.ref
 | 
			
		||||
    # Wait for the Mix setup to finish and for node initialization
 | 
			
		||||
    assert_receive {:emitter, ^ref, {:output, "Running mix deps.get...\n"}}, 5_000
 | 
			
		||||
    assert_receive {:emitter, ^ref, {:ok, runtime}}, 5_000
 | 
			
		||||
 | 
			
		||||
    Runtime.connect(runtime)
 | 
			
		||||
    %{node: node} = runtime
 | 
			
		||||
 | 
			
		||||
    # Make sure the node is running.
 | 
			
		||||
    Node.monitor(node, true)
 | 
			
		||||
    assert :pong = Node.ping(node)
 | 
			
		||||
 | 
			
		||||
    # Ensure the initialization works
 | 
			
		||||
    assert evaluator_module_loaded?(node)
 | 
			
		||||
    assert manager_started?(node)
 | 
			
		||||
 | 
			
		||||
    # Ensure modules from the Mix project are available
 | 
			
		||||
    assert :rpc.call(node, Project, :hello, []) == "hello"
 | 
			
		||||
 | 
			
		||||
    # Disconnecting should also terminate the node
 | 
			
		||||
    Runtime.disconnect(runtime)
 | 
			
		||||
    assert_receive {:nodedown, ^node}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  defp evaluator_module_loaded?(node) do
 | 
			
		||||
    :rpc.call(node, :code, :is_loaded, [Livebook.Evaluator]) != false
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  defp manager_started?(node) do
 | 
			
		||||
    :rpc.call(node, Process, :whereis, [Livebook.Runtime.ErlDist.Manager]) != nil
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										1
									
								
								test/support/project/.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								test/support/project/.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
/_build/
 | 
			
		||||
							
								
								
									
										5
									
								
								test/support/project/lib/project.ex
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								test/support/project/lib/project.ex
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
defmodule Project do
 | 
			
		||||
  @moduledoc false
 | 
			
		||||
 | 
			
		||||
  def hello, do: "hello"
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										19
									
								
								test/support/project/mix.exs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								test/support/project/mix.exs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
defmodule Project.MixProject do
 | 
			
		||||
  use Mix.Project
 | 
			
		||||
 | 
			
		||||
  def project do
 | 
			
		||||
    [
 | 
			
		||||
      app: :project,
 | 
			
		||||
      version: "0.1.0",
 | 
			
		||||
      elixir: "~> 1.11",
 | 
			
		||||
      start_permanent: Mix.env() == :prod,
 | 
			
		||||
      deps: []
 | 
			
		||||
    ]
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def application do
 | 
			
		||||
    [
 | 
			
		||||
      extra_applications: [:logger]
 | 
			
		||||
    ]
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue