2

Now I’m working with Erlang, and I think I should do some distributed test with the common test framework. I’v read some article about this. But I can’t run my own application on multiple nodes with the ct_master. It Bothers me many days — the slave nodes cannot include my own application. Can you give me some notice about this?

dir tree:

$ tree
.
├── logs
├── src
│   ├── aaa.app.src
│   ├── aaa_app.erl
│   └── aaa_sup.erl
└── test
    ├── aaa_SUITE.erl
    ├── dist.spec
    └── spec

And the test suite is:

-module(aaa_SUITE).
-include_lib("common_test/include/ct.hrl").

-compile(export_all).
suite() -> [{timetrap, {seconds, 20}}].
groups() -> [].
all() ->
    [ {exports, Functions} | _ ] = ?MODULE:module_info(),
    [ FName || {FName, _} <- lists:filter(
                               fun ({module_info,_}) -> false;
                                   ({all,_}) -> false;
                                   ({init_per_suite,1}) -> false;
                                   ({end_per_suite,1}) -> false;
                                   ({_,1}) -> true;
                                   ({_,_}) -> false
                               end, Functions)].
init_per_suite(Config) ->
    Config.
end_per_suite(_Config) ->
    ok.
init_per_group(_group, Config) ->
    Config.
end_per_group(_group, Config) ->
    Config.
init_per_testcase(TestCase, Config) ->
    Config.
end_per_testcase(TestCase, Config) ->
    Config.

test_aaa(_Config) ->
    ok = application:start(aaa).

the spec file is:

{node, a_1, 'a1@localhost'}.

{include, [a_1], ["../ebin"]}.
{init, [a_1], [{node_start, [{monitor_master, true}]}, {erl_flags, "-pa ../ebin"}]}.

{logdir, all_nodes, "../logs/"}.
{logdir, master, "../logs/"}.

{alias, aaa, "./"}.
{suites, [a_1], aaa, all}.

I just run erl -name ct@localhost, then run ct_master:run("test/dist.spec") in the erlang shell.

The common test always exit with message {badmatch,{error,{"no such file or directory","aaa.app"}}}.

Sirui Zhuang
  • 665
  • 5
  • 12

1 Answers1

0

I would definitely consider this a hack but something like this might help:

%% Run the app locally
{ok, _MasterApps} = application:ensure_all_started(my_app),
%% Adding our local code paths to the remote node to ensure
%% proper path resolution
ok = rpc:call(Slave, code, add_pathsz, [code:get_path()]),
%% Start the application remotely
{ok, _SlaveApps} = rpc:call(Slave, application, ensure_all_started, [my_app]).