···1212 Kernel.send(dest, message)
1313 end
14141515+ @spec spawn_node(atom, function) :: pid
1616+ def spawn_node(node, fun) do
1717+ case get_sim() do
1818+ nil -> raise "spawn_node() only works in simulation"
1919+ _sim -> Scheduler.spawn_node_and_yield(fun, node, false)
2020+ end
2121+ end
2222+1523 @spec alias :: reference
1624 def alias do
1725 case get_sim() do
+4
lib/trinity/sim_server.ex
···1111 SimGen.start_link(module, arg, options)
1212 end
13131414+ def start(module, arg, options \\ []) do
1515+ SimGen.start(module, arg, options)
1616+ end
1717+1418 @spec call(GenServer.server, term, timeout) :: term
1519 def call(server, request, timeout \\ 5000) do
1620 case get_sim() do
+9-4
test/trinity_test.exs
···11defmodule TrinityTest do
22 use ExUnit.Case
3344- alias Trinity.Scheduler
44+ alias Trinity.{SimProcess, Scheduler}
5566 defmodule Counter do
77 use GenServer
···22222323 test "scheduler" do
2424 Scheduler.run_simulation(fn ->
2525+ nodes = [:n1, :n2, :n3]
2526 pids =
2626- Enum.map(1..10, fn i ->
2727- {:ok, pid} = Counter.start_link(i)
2828- pid
2727+ Enum.map(nodes, fn i ->
2828+ Enum.map(1..10, fn i ->
2929+ {:ok, pid} = Counter.start_link(i)
3030+ pid
3131+ end)
2932 end)
3333+ |> Enum.concat()
3434+3035 dbg pids
31363237 Enum.each(pids, fn pid ->