Does anyone know of an example/blog post about integration testing that involves bringing up another beam instance and running code in the new instance? It can be with or without clustering since I’m not sure about the trade-offs involved there.
2 Likes
Pretty manual but we’re starting multiple beams for our peer to peer networking test: https://github.com/diodechain/diode_server_ex/blob/44c02a45c204fae635cb06642b208c1ca25b4e48/test/test_helper.exs#L77
This is the core snippet:
spawn_link(fn ->
iex = System.find_executable("iex")
args = ["--cookie", @cookie, "-S", "mix", "run"]
env =
[
{"MIX_ENV", "test"},
{"DATA_DIR", clonedir},
{"RPC_PORT", "#{rpc_port(num)}"},
{"RPCS_PORT", "#{rpcs_port(num)}"},
{"EDGE2_PORT", "#{edge2_port(num)}"},
{"PEER_PORT", "#{peer_port(num)}"},
{"SEED", "none"}
]
|> Enum.map(fn {key, value} -> {String.to_charlist(key), String.to_charlist(value)} end)
port =
Port.open({:spawn_executable, iex}, [
{:args, args},
{:env, env},
:stream,
:exit_status,
:hide,
:use_stdio,
:stderr_to_stdout
])
true = Process.register(port, String.to_atom("clone_#{num}"))
clone_loop(port, file)
end)
2 Likes
You can take a look at the archived firenest repo, which iirc did do multi node testing.
1 Like
Thanks for all the examples! I’ll take a look at them and base my work on them.
1 Like