Browse Source

Allow benchmark to get hosts from config file.

Roberto Ostinelli 5 years ago
parent
commit
a11d0f4bed
3 changed files with 30 additions and 7 deletions
  1. 3 0
      test/syn_benchmark.config
  2. 13 5
      test/syn_benchmark.erl
  3. 14 2
      test/syn_test_suite_helper.erl

+ 3 - 0
test/syn_benchmark.config

@@ -0,0 +1,3 @@
+{remote_nodes, [
+    %% #{node => node_name, host => host, user => "user", pass => "pass"}
+]}.

+ 13 - 5
test/syn_benchmark.erl

@@ -41,14 +41,22 @@
 %% API
 %% ===================================================================
 start() ->
+    io:format("-----> Starting benchmark on node ~s~n", [node()]),
     %% init
-    NodeCount = list_to_integer(os:getenv("SYN_BENCH_NODE_COUNT", "2")),
+    ConfigFilePath = filename:join([filename:dirname(code:which(?MODULE)), "syn_benchmark.config"]),
+    {ok, BenchConfig} = file:consult(ConfigFilePath),
+    RemoteHosts = proplists:get_value(remote_nodes, BenchConfig, []),
     ProcessCount = list_to_integer(os:getenv("SYN_PROCESS_COUNT", "100000")),
     %% start nodes
-    lists:foreach(fun(Count) ->
-        ShortName = list_to_atom("syn_bench_slave_" ++ integer_to_list(Count)),
-        {ok, _} = syn_test_suite_helper:start_slave(ShortName)
-    end, lists:seq(1, NodeCount - 1)),
+    lists:foreach(fun(RemoteHost) ->
+        io:format("-----> Starting slave node ~s@~s~n", [maps:get(node, RemoteHost), maps:get(host, RemoteHost)]),
+        {ok, _} = syn_test_suite_helper:start_slave(
+            maps:get(node, RemoteHost),
+            maps:get(host, RemoteHost),
+            maps:get(user, RemoteHost),
+            maps:get(pass, RemoteHost)
+        )
+    end, RemoteHosts),
 
     Nodes = [node() | nodes()],
     io:format("-----> Started ~p nodes: ~p~n", [length(Nodes), Nodes]),

+ 14 - 2
test/syn_test_suite_helper.erl

@@ -26,7 +26,8 @@
 -module(syn_test_suite_helper).
 
 %% API
--export([start_slave/1, stop_slave/1]).
+-export([start_slave/1, start_slave/4]).
+-export([stop_slave/1, stop_slave/2]).
 -export([connect_node/1, disconnect_node/1]).
 -export([clean_after_test/0]).
 -export([start_process/0, start_process/1, start_process/2]).
@@ -41,13 +42,24 @@
 %% API
 %% ===================================================================
 start_slave(NodeShortName) ->
-    CodePath = code:get_path(),
     {ok, Node} = ct_slave:start(NodeShortName, [{boot_timeout, 10}]),
+    CodePath = code:get_path(),
+    true = rpc:call(Node, code, set_path, [CodePath]),
+    {ok, Node}.
+start_slave(NodeShortName, Host, Username, Password) ->
+    {ok, Node} = ct_slave:start(Host, NodeShortName, [
+        {boot_timeout, 10},
+        {username, Username},
+        {password, Password}
+    ]),
+    CodePath = code:get_path(),
     true = rpc:call(Node, code, set_path, [CodePath]),
     {ok, Node}.
 
 stop_slave(NodeShortName) ->
     {ok, _} = ct_slave:stop(NodeShortName).
+stop_slave(Host, NodeShortName) ->
+    {ok, _} = ct_slave:stop(Host, NodeShortName).
 
 connect_node(Node) ->
     net_kernel:connect_node(Node).