Skip to content

Commit

Permalink
Merge pull request #672 from basho/feature/jra/decouple-harness
Browse files Browse the repository at this point in the history
Create test harness behavior; refactor current harnesses
  • Loading branch information
bowrocker committed Aug 6, 2014
2 parents 741b9ed + b3a8867 commit cd6a969
Show file tree
Hide file tree
Showing 13 changed files with 865 additions and 73 deletions.
26 changes: 13 additions & 13 deletions src/rt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ priv_dir() ->

%% @doc gets riak deps from the appropriate harness
-spec get_deps() -> list().
get_deps() -> ?HARNESS:get_deps().
get_deps() -> rt_harness:get_deps().

%% @doc if String contains Substr, return true.
-spec str(string(), string()) -> boolean().
Expand Down Expand Up @@ -164,26 +164,26 @@ maybe_wait_for_changes(Node) ->

%% @doc Spawn `Cmd' on the machine running the test harness
spawn_cmd(Cmd) ->
?HARNESS:spawn_cmd(Cmd).
rt_harness:spawn_cmd(Cmd).

%% @doc Spawn `Cmd' on the machine running the test harness
spawn_cmd(Cmd, Opts) ->
?HARNESS:spawn_cmd(Cmd, Opts).
rt_harness:spawn_cmd(Cmd, Opts).

%% @doc Wait for a command spawned by `spawn_cmd', returning
%% the exit status and result
wait_for_cmd(CmdHandle) ->
?HARNESS:wait_for_cmd(CmdHandle).
rt_harness:wait_for_cmd(CmdHandle).

%% @doc Spawn `Cmd' on the machine running the test harness, returning
%% the exit status and result
cmd(Cmd) ->
?HARNESS:cmd(Cmd).
rt_harness:cmd(Cmd).

%% @doc Spawn `Cmd' on the machine running the test harness, returning
%% the exit status and result
cmd(Cmd, Opts) ->
?HARNESS:cmd(Cmd, Opts).
rt_harness:cmd(Cmd, Opts).

%% @doc pretty much the same as os:cmd/1 but it will stream the output to lager.
%% If you're running a long running command, it will dump the output
Expand Down Expand Up @@ -545,15 +545,15 @@ enable_search_hook(Node, Bucket) when is_binary(Bucket) ->
%% or something like that, it's the version you're upgrading to.
-spec get_version() -> binary().
get_version() ->
?HARNESS:get_version().
rt_harness:get_version().

%% @doc outputs some useful information about nodes that are up
whats_up() ->
?HARNESS:whats_up().
rt_harness:whats_up().

-spec get_ip(node()) -> string().
get_ip(Node) ->
?HARNESS:get_ip(Node).
rt_harness:get_ip(Node).

%% @doc Log a message to the console of the specified test nodes.
%% Messages are prefixed by the string "---riak_test--- "
Expand Down Expand Up @@ -595,12 +595,12 @@ pmap(F, L) ->

%% @private
setup_harness(Test, Args) ->
?HARNESS:setup_harness(Test, Args).
rt_harness:setup_harness(Test, Args).

%% @doc Downloads any extant log files from the harness's running
%% nodes.
get_node_logs() ->
?HARNESS:get_node_logs().
rt_harness:get_node_logs().

check_ibrowse() ->
try sys:get_status(ibrowse) of
Expand Down Expand Up @@ -741,7 +741,7 @@ wait_for_control(VersionedNodes) when is_list(VersionedNodes) ->
[wait_for_control(Vsn, Node) || {Vsn, Node} <- VersionedNodes].

node_id(Node) ->
?HARNESS:node_id(Node).
rt_harness:node_id(Node).

node_version(Node) ->
?HARNESS:node_version(Node).
rt_harness:node_version(Node).
2 changes: 1 addition & 1 deletion src/rt_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ make_multi_backend_config(Other) ->
make_multi_backend_config(default).

get_backends() ->
Backends = ?HARNESS:get_backends(),
Backends = rt_harness:get_backends(),
case Backends of
[riak_kv_bitcask_backend] -> bitcask;
[riak_kv_eleveldb_backend] -> eleveldb;
Expand Down
10 changes: 5 additions & 5 deletions src/rt_cluster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ deploy_nodes(NumNodes, InitialConfig) when is_integer(NumNodes) ->
deploy_nodes(NodeConfig);
deploy_nodes(Versions, Services) ->
NodeConfig = [ rt_config:version_to_config(Version) || Version <- Versions ],
Nodes = ?HARNESS:deploy_nodes(NodeConfig),
Nodes = rt_harness:deploy_nodes(NodeConfig),
lager:info("Waiting for services ~p to start on ~p.", [Services, Nodes]),
[ ok = rt:wait_for_service(Node, Service) || Node <- Nodes,
Service <- Services ],
Expand All @@ -109,7 +109,7 @@ deploy_clusters(Settings) ->
{NumNodes, Vsn, InitialConfig} when is_integer(NumNodes) ->
[{Vsn, InitialConfig} || _ <- lists:seq(1,NumNodes)]
end || Setting <- Settings],
?HARNESS:deploy_clusters(ClusterConfigs).
rt_harness:deploy_clusters(ClusterConfigs).

build_clusters(Settings) ->
Clusters = deploy_clusters(Settings),
Expand Down Expand Up @@ -200,7 +200,7 @@ clean_data_dir(Nodes) ->
clean_data_dir(Nodes, SubDir) when not is_list(Nodes) ->
clean_data_dir([Nodes], SubDir);
clean_data_dir(Nodes, SubDir) when is_list(Nodes) ->
?HARNESS:clean_data_dir(Nodes, SubDir).
rt_harness:clean_data_dir(Nodes, SubDir).

%% @doc Shutdown every node, this is for after a test run is complete.
teardown() ->
Expand All @@ -209,10 +209,10 @@ teardown() ->
%%[ rt_node:stop(Node) || Node <- nodes()],
%% Then do the more exhaustive harness thing, in case something was up
%% but not connected.
?HARNESS:teardown().
rt_harness:teardown().

versions() ->
?HARNESS:versions().
rt_harness:versions().

augment_config(Section, Property, Config) ->
UpdSectionConfig = update_section(Section,
Expand Down
12 changes: 6 additions & 6 deletions src/rt_cmd_line.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@

%% @doc Call 'bin/riak-admin' command on `Node' with arguments `Args'
admin(Node, Args) ->
?HARNESS:admin(Node, Args).
rt_harness:admin(Node, Args).

%% @doc Call 'bin/riak' command on `Node' with arguments `Args'
riak(Node, Args) ->
?HARNESS:riak(Node, Args).
rt_harness:riak(Node, Args).


%% @doc Call 'bin/riak-repl' command on `Node' with arguments `Args'
riak_repl(Node, Args) ->
?HARNESS:riak_repl(Node, Args).
rt_harness:riak_repl(Node, Args).

search_cmd(Node, Args) ->
{ok, Cwd} = file:get_cwd(),
Expand All @@ -65,14 +65,14 @@ search_cmd(Node, Args) ->
%% expect will process based on the output following the sent data.
%%
attach(Node, Expected) ->
?HARNESS:attach(Node, Expected).
rt_harness:attach(Node, Expected).

%% @doc Runs 'riak attach-direct' on a specific node
%% @see rt_cmd_line:attach/2
attach_direct(Node, Expected) ->
?HARNESS:attach_direct(Node, Expected).
rt_harness:attach_direct(Node, Expected).

%% @doc Runs `riak console' on a specific node
%% @see rt_cmd_line:attach/2
console(Node, Expected) ->
?HARNESS:console(Node, Expected).
rt_harness:console(Node, Expected).
12 changes: 6 additions & 6 deletions src/rt_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,30 @@ config_or_os_env(Config, Default) ->

-spec set_conf(atom(), [{string(), string()}]) -> ok.
set_conf(all, NameValuePairs) ->
?HARNESS:set_conf(all, NameValuePairs);
rt_harness:set_conf(all, NameValuePairs);
set_conf(Node, NameValuePairs) ->
rt_node:stop(Node),
?assertEqual(ok, rt:wait_until_unpingable(Node)),
?HARNESS:set_conf(Node, NameValuePairs),
rt_harness:set_conf(Node, NameValuePairs),
rt_node:start(Node).

-spec set_advanced_conf(atom(), [{string(), string()}]) -> ok.
set_advanced_conf(all, NameValuePairs) ->
?HARNESS:set_advanced_conf(all, NameValuePairs);
rt_harness:set_advanced_conf(all, NameValuePairs);
set_advanced_conf(Node, NameValuePairs) ->
rt_node:stop(Node),
?assertEqual(ok, rt:wait_until_unpingable(Node)),
?HARNESS:set_advanced_conf(Node, NameValuePairs),
rt_harness:set_advanced_conf(Node, NameValuePairs),
rt_node:start(Node).

%% @doc Rewrite the given node's app.config file, overriding the varialbes
%% in the existing app.config with those in `Config'.
update_app_config(all, Config) ->
?HARNESS:update_app_config(all, Config);
rt_harness:update_app_config(all, Config);
update_app_config(Node, Config) ->
rt_node:stop(Node),
?assertEqual(ok, rt:wait_until_unpingable(Node)),
?HARNESS:update_app_config(Node, Config),
rt_harness:update_app_config(Node, Config),
rt_node:start(Node).

version_to_config(Config) when is_tuple(Config)-> Config;
Expand Down
77 changes: 49 additions & 28 deletions src/rt_cs_dev.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,41 @@

%% @private
-module(rt_cs_dev).
-compile(export_all).
-behaviour(test_harness).

-export([start/1,
stop/1,
deploy_clusters/1,
clean_data_dir/2,
create_dirs/1,
spawn_cmd/1,
spawn_cmd/2,
cmd/1,
cmd/2,
setup_harness/2,
get_version/0,
get_backends/0,
get_deps/0,
set_backend/1,
whats_up/0,
get_ip/1,
node_id/1,
node_version/1,
admin/2,
riak/2,
attach/2,
attach_direct/2,
console/2,
update_app_config/2,
teardown/0,
set_conf/2,
set_advanced_conf/2,
upgrade/2,
deploy_nodes/1,
versions/0,
get_node_logs/0,
get_node_logs/1]).

-include_lib("eunit/include/eunit.hrl").

-define(DEVS(N), lists:concat(["dev", N, "@127.0.0.1"])).
Expand All @@ -31,6 +65,12 @@
get_deps() ->
lists:flatten(io_lib:format("~s/dev/dev1/lib", [relpath(current)])).

deploy_clusters(ClusterConfig) ->
rt_harness_util:deploy_clusters(ClusterConfig).

get_ip(Node) ->
rt_harness_util:get_ip(Node).

setup_harness(_Test, _Args) ->
Path = relpath(root),
%% Stop all discoverable nodes, not just nodes we'll be using for this test.
Expand Down Expand Up @@ -61,10 +101,6 @@ relpath(Vsn) ->
Path = ?BUILD_PATHS,
path(Vsn, Path).

srcpath(Vsn) ->
Path = ?SRC_PATHS,
path(Vsn, Path).

path(Vsn, Paths=[{_,_}|_]) ->
orddict:fetch(Vsn, orddict:from_list(Paths));
path(current, Path) ->
Expand Down Expand Up @@ -225,19 +261,6 @@ rm_dir(Dir) ->
?assertCmd("rm -rf " ++ Dir),
?assertEqual(false, filelib:is_dir(Dir)).

add_default_node_config(Nodes) ->
case rt_config:get(rt_default_config, undefined) of
undefined -> ok;
Defaults when is_list(Defaults) ->
rt:pmap(fun(Node) ->
update_app_config(Node, Defaults)
end, Nodes),
ok;
BadValue ->
lager:error("Invalid value for rt_default_config : ~p", [BadValue]),
throw({invalid_config, {rt_default_config, BadValue}})
end.

deploy_nodes(NodeConfig) ->
Path = relpath(root),
lager:info("Riak path: ~p", [Path]),
Expand All @@ -249,14 +272,14 @@ deploy_nodes(NodeConfig) ->
VersionMap = lists:zip(NodesN, Versions),

%% Check that you have the right versions available
[ check_node(Version) || Version <- VersionMap ],
[ rt_harness_util:check_node(Version) || Version <- VersionMap ],
rt_config:set(rt_nodes, NodeMap),
rt_config:set(rt_versions, VersionMap),

create_dirs(Nodes),

%% Set initial config
add_default_node_config(Nodes),
rt_harness_util:add_default_node_config(Nodes),
rt:pmap(fun({_, default}) ->
ok;
({Node, Config}) ->
Expand Down Expand Up @@ -482,14 +505,6 @@ get_cmd_result(Port, Acc) ->
timeout
end.

check_node({_N, Version}) ->
case proplists:is_defined(Version, rt_config:get(build_paths)) of
true -> ok;
_ ->
lager:error("You don't have Riak ~s installed or configured", [Version]),
erlang:error("You don't have Riak " ++ atom_to_list(Version) ++ " installed or configured")
end.

set_backend(Backend) ->
lager:info("rtdev:set_backend(~p)", [Backend]),
update_app_config(all, [{riak_kv, [{storage_backend, Backend}]}]),
Expand Down Expand Up @@ -532,3 +547,9 @@ get_node_logs(Base) ->
{ok, Port} = file:open(Filename, [read, binary]),
{lists:nthtail(RootLen, Filename), Port}
end || Filename <- filelib:wildcard(Root ++ "/*/dev/dev*/log/*") ].

set_advanced_conf(Node, NameValuePairs) ->
rt_harness_util:set_advanced_conf(Node, NameValuePairs).

set_conf(Node, NameValuePairs) ->
rt_harness_util:set_conf(Node, NameValuePairs).
Loading

0 comments on commit cd6a969

Please sign in to comment.