Code loading on remote test nodes using `peer`

Lets say that we want to test application app1 that has dependencies to dep1 and dep2. How do I spawn slaves that has those 3 applications loaded or at least path to binaries in their code path? I want to avoid manually adding path for every app and loading it via erpc.

1 Like

There are multiple options (although I think adding code path via RPC is the easiest):

  1. Work with releases. There is code example in the documentation that works with Docker - by building the release (see “build_release” function definition).
Release = {release, {"lambda", "1.0.0"},
              {erts, erlang:system_info(version)},
              [{App, begin {ok, Vsn} = application:get_key(App, vsn), Vsn end}
                  || App <- [kernel, stdlib, sasl]]},
          ok = file:write_file(RelFile, list_to_binary(lists:flatten(
              io_lib:format("~tp.", [Release])))),
          RelFileNoExt = filename:join(Dir, "lambda"),

          %% create boot script
          {ok, systools_make, []} = systools:make_script(RelFileNoExt,
              [silent, {outdir, Dir}]),

  1. Pass paths in the ?CT_PEER startup arguments:
Paths = lists:append([["-pa", code:lilb_dir(App)] || App <- [app1, app2, app3]),
{ok, Peer, Node} = ?CT_PEER(Paths)
  1. Load code paths in bulk via rpc: erpc:call(code, add_paths, [code:get_path()])

You may also explore LIB_DIR environment variable, e.g. ?CT_PEER(["-env", "LIB_DIR", RootFolder]) - I haven’t tried it but it may also work.


Yes, code:lib_dir/1 was something I was looking for, thank You! If I’ll make it with LIB_DIR I’ll post it here :smiley:

1 Like