Hi!
I’m updating some tests that were originally written for OTP 21 to OTP 25 that I run like this:
rebar3 ct --name test@127.0.0.1
.
The idea behind the tests is to have 3 nodes running, and I start them like this:
init_per_suite(Config) ->
Node1 = 'node1@127.0.0.1',
Node2 = 'node2@127.0.0.1',
Node3 = 'node3@127.0.0.1',
start_node(Node1, 8198, 8199),
start_node(Node2, 8298, 8299),
start_node(Node3, 8398, 8399),
build_cluster(Node1, Node2, Node3),
[{node1, Node1},
{node2, Node2},
{node3, Node3} | Config].
And the start_node implementation is as follows:
start_node(NodeName, WebPort, HandoffPort) →
%% need to set the code path so the same modules are available in the slave
CodePath = code:get_path(),
PathFlag = "-pa " ++ lists:concat(lists:join(" ", CodePath)),
{ok, _} = ct_slave:start(NodeName, [{erl_flags, PathFlag}]),
%% set the required environment for riak core
DataDir = "./data/" ++ atom_to_list(NodeName),
rpc:call(NodeName, application, load, [riak_core]),
rpc:call(NodeName, application, set_env, [riak_core, ring_state_dir, DataDir]),
rpc:call(NodeName, application, set_env, [riak_core, platform_data_dir, DataDir]),
rpc:call(NodeName, application, set_env, [riak_core, web_port, WebPort]),
rpc:call(NodeName, application, set_env, [riak_core, handoff_port, HandoffPort]),
rpc:call(NodeName, application, set_env, [riak_core, schema_dirs, ["../../lib/rc_example/priv"]]),
%% start the rc_example app
{ok, _} = rpc:call(NodeName, application, ensure_all_started, [rc_example]),
ok.
Everything works fine like this, but I get the following warning:
test/key_value_SUITE.erl:86:13: Warning: ct_slave:start/2 is deprecated and will be removed in OTP 27; use ?CT_PEER(), or the 'peer' module instead
test/key_value_SUITE.erl:103:3: Warning: ct_slave:stop/1 is deprecated and will be removed in OTP 27; use ?CT_PEER(), or the 'peer' module instead
I have tried to use and alternative implementation with both CT_PEER and peer:start, like this:
`start_node(NodeName, Host, WebPort, HandoffPort) ->
%% need to set the code path so the same modules are available in the slave
CodePath = code:get_path(),
PathFlag = "-pa " ++ lists:concat(lists:join(" ", CodePath)),
{ok, _Peer, Node} = ?CT_PEER(["-name " ++ NodeName ++ "@" ++ Host, PathFlag]),
%% set the required environment for riak core
DataDir = "./data/" ++ NodeName,
%% Check the node is running
ok = rpc:call(Node, application, load, [riak_core]),
ok = rpc:call(Node, application, set_env, [riak_core, ring_state_dir, DataDir]),
ok = rpc:call(Node, application, set_env, [riak_core, platform_data_dir, DataDir]),
ok = rpc:call(Node, application, set_env, [riak_core, web_port, WebPort]),
ok = rpc:call(Node, application, set_env, [riak_core, handoff_port, HandoffPort]),
ok = rpc:call(Node, application, set_env, [riak_core, schema_dirs, ["../../lib/rc_example/priv"]]),
%% start the rc_example app
{ok, _} = rpc:call(Node, application, ensure_all_started, [rc_example]),
Node.
%%
And change init to:
init_per_suite(Config) ->
%% Node1 = 'node1@127.0.0.1',
%% Node2 = 'node2@127.0.0.1',
%% Node3 = 'node3@127.0.0.1',
Host = "127.0.0.1",
Node1 = start_node("node1", Host, 8198, 8199),
Node2 = start_node("node2", Host, 8298, 8299),
Node3 = start_node("node3", Host, 8398, 8399),
build_cluster(Node1, Node2, Node3),
[{node1, Node1},
{node2, Node2},
{node3, Node3} | Config].
But then, the test fails with a timeout, what could I be doing wrong?
Edit:
Here’s the code, you should be able to reproduce the error by:
- Cloning.
- git checkout non_working_tests
- make test