Skip to content

Commit d893259

Browse files
author
Brett Hazen
committed
Convert giddyup module into a gen_server
- Always copy log files to local directory - Removed unused command-line options in escript - Get rid of extraneous commented-out code - Move as much GiddyUp-specific logic into `giddyup' - Correctly upload config files - Upload files asynchronously to scheduler can reclaim used nodes
1 parent 18fe0bf commit d893259

File tree

9 files changed

+475
-241
lines changed

9 files changed

+475
-241
lines changed

src/giddyup.erl

Lines changed: 382 additions & 73 deletions
Large diffs are not rendered by default.

src/riak_test_escript.erl

Lines changed: 40 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,19 @@ main(Args) ->
3636
ensure_dir(OutDir),
3737
lager_setup(OutDir),
3838

39-
{Tests, NonTests} = generate_test_lists(ParsedArgs),
39+
%% Do we use GiddyUp for this run?
40+
Platform = report_platform(ParsedArgs),
41+
UseGiddyUp = case Platform of
42+
undefined -> false;
43+
_ -> true
44+
end,
45+
start_giddyup(Platform),
46+
{Tests, NonTests} = generate_test_lists(UseGiddyUp, ParsedArgs),
4047

4148
ok = prepare(ParsedArgs, Tests, NonTests),
4249
Results = execute(Tests, OutDir, ParsedArgs),
43-
finalize(Results, ParsedArgs).
50+
finalize(Results, ParsedArgs),
51+
stop_giddyup(UseGiddyUp).
4452

4553
% @doc Validate the command-line options
4654
parse_args(Args) ->
@@ -64,14 +72,11 @@ cli_options() ->
6472
{help, $h, "help", undefined, "Print this usage page"},
6573
{config, $c, "conf", string, "specifies the project configuration"},
6674
{tests, $t, "tests", string, "specifies which tests to run"},
67-
{suites, $s, "suites", string, "which suites to run"},
68-
{groups, $g, "groups", string, "specifiy a list of test groups to run"},
6975
{dir, $d, "dir", string, "run all tests in the specified directory"},
7076
{skip, $x, "skip", string, "list of tests to skip in a directory"},
7177
{verbose, $v, "verbose", undefined, "verbose output"},
7278
{outdir, $o, "outdir", string, "output directory"},
7379
{backend, $b, "backend", atom, "backend to test [memory | bitcask | eleveldb]"},
74-
{upgrade_path, $u, "upgrade-path", atom, "comma-separated list representing an upgrade path (e.g. riak-1.3.4,riak_ee-1.4.12,riak_ee-2.0.0)"},
7580
{keep, undefined, "keep", boolean, "do not teardown cluster"},
7681
{continue_on_fail, $n, "continue", boolean, "continues executing tests on failure"},
7782
{report, $r, "report", string, "you're reporting an official test run, provide platform info (e.g. ubuntu-1404-64)\nUse 'config' if you want to pull from ~/.riak_test.config"},
@@ -93,13 +98,13 @@ report_platform(ParsedArgs) ->
9398
end.
9499

95100
%% @doc Print help string if it's specified, otherwise parse the arguments
96-
generate_test_lists(ParsedArgs) ->
101+
generate_test_lists(UseGiddyUp, ParsedArgs) ->
97102
%% Have to load the `riak_test' config prior to assembling the
98103
%% test metadata
99104

100105
TestData = compose_test_data(ParsedArgs),
101-
Backend = proplists:get_value(backend, ParsedArgs, bitcask),
102-
{Tests, NonTests} = wrap_test_in_test_plan(report_platform(ParsedArgs), Backend, TestData),
106+
Backends = [proplists:get_value(backend, ParsedArgs, bitcask)],
107+
{Tests, NonTests} = wrap_test_in_test_plan(UseGiddyUp, Backends, TestData),
103108
Offset = rt_config:get(offset, undefined),
104109
Workers = rt_config:get(workers, undefined),
105110
shuffle_tests(Tests, NonTests, Offset, Workers).
@@ -168,24 +173,6 @@ execute(TestPlans, OutDir, ParsedArgs) ->
168173
self()),
169174
wait_for_results(Executor, [], length(TestPlans), 0).
170175

171-
%% TestResults = run_tests(Tests, Outdir, Report, HarnessArgs),
172-
%% lists:filter(fun results_filter/1, TestResults).
173-
174-
%% run_test(Test, Outdir, TestMetaData, Report, HarnessArgs, NumTests) ->
175-
%% rt_cover:maybe_start(Test),
176-
%% SingleTestResult = riak_test_runner:run(Test, Outdir, TestMetaData, HarnessArgs),
177-
178-
%% case NumTests of
179-
%% 1 -> keep_them_up;
180-
%% _ -> rt_cluster:teardown()
181-
%% end,
182-
183-
%% TODO: Do this in the test runner
184-
%% CoverDir = rt_config:get(cover_output, "coverage"),
185-
%% CoverFile = rt_cover:maybe_export_coverage(Test, CoverDir, erlang:phash2(TestMetaData)),
186-
%% publish_report(SingleTestResult, CoverFile, Report),
187-
188-
%% [{coverdata, CoverFile} | SingleTestResult].
189176

190177
%% TODO: Use `TestCount' and `Completed' to display progress output
191178
wait_for_results(Executor, TestResults, TestCount, Completed) ->
@@ -249,9 +236,6 @@ erlang_setup(_ParsedArgs) ->
249236
register(riak_test, self()),
250237
maybe_add_code_path("./ebin"),
251238

252-
%% ibrowse
253-
load_and_start(ibrowse),
254-
255239
%% Sets up extra paths earlier so that tests can be loadable
256240
%% without needing the -d flag.
257241
code:add_paths(rt_config:get(test_paths, [])),
@@ -274,10 +258,6 @@ maybe_add_code_path(Path, true) ->
274258
maybe_add_code_path(_, false) ->
275259
meh.
276260

277-
load_and_start(Application) ->
278-
application:load(Application),
279-
application:start(Application).
280-
281261
ensure_dir(undefined) ->
282262
ok;
283263
ensure_dir(Dir) ->
@@ -358,21 +338,18 @@ extract_test_names(Test, {CodePaths, TestNames}) ->
358338
%% @doc Determine which tests to run based on command-line argument
359339
%% If the platform is defined, consult GiddyUp, otherwise just shovel
360340
%% the whole thing into the Planner
361-
-spec(load_up_test_planner(string() | undefined, string(), list()) -> list()).
362-
load_up_test_planner(undefined, Backend, CommandLineTests) ->
363-
[rt_planner:add_test_plan(Name, undefined, Backend, undefined, undefined) || Name <- CommandLineTests];
364-
%% GiddyUp Flavor
365-
load_up_test_planner(Platform, Backend, CommandLineTests) ->
366-
rt_planner:load_from_giddyup(Platform, Backend, CommandLineTests).
341+
-spec(load_up_test_planner(boolean(), [string()], list()) -> list()).
342+
load_up_test_planner(true, Backends, CommandLineTests) ->
343+
rt_planner:load_from_giddyup(Backends, CommandLineTests);
344+
load_up_test_planner(_, Backends, CommandLineTests) ->
345+
[rt_planner:add_test_plan(Name, undefined, Backends, undefined, undefined) || Name <- CommandLineTests].
367346

368347
%% @doc Push all of the test into the Planner for now and wrap them in an `rt_test_plan'
369348
%% TODO: Let the Planner do the work, not the riak_test_executor
370-
-spec(wrap_test_in_test_plan(string(), string(), [atom()]) -> {list(), list()}).
371-
wrap_test_in_test_plan(Platform, Backend, CommandLineTests) ->
372-
%% ibrowse neededfor GiddyUp
373-
load_and_start(ibrowse),
349+
-spec(wrap_test_in_test_plan(boolean(), [string()], [atom()]) -> {list(), list()}).
350+
wrap_test_in_test_plan(UseGiddyUp, Backends, CommandLineTests) ->
374351
{ok, _Pid} = rt_planner:start_link(),
375-
load_up_test_planner(Platform, Backend, CommandLineTests),
352+
load_up_test_planner(UseGiddyUp, Backends, CommandLineTests),
376353
TestPlans = [rt_planner:fetch_test_plan() || _ <- lists:seq(1, rt_planner:number_of_plans())],
377354
NonRunnableTestPlans = [rt_planner:fetch_test_non_runnable_plan() || _ <- lists:seq(1, rt_planner:number_of_non_runable_plans())],
378355
rt_planner:stop(),
@@ -407,26 +384,6 @@ match_group_attributes(Attributes, Groups) ->
407384
|| Group <- Groups, TestType <- TestTypes ])
408385
end.
409386

410-
%% run_tests(Tests, Outdir, Report, HarnessArgs) ->
411-
%% Need properties for tests prior to getting here Need server to
412-
%% manage the aquisition of nodes and to handle comparison of test
413-
%% `node_count' property with resources available. Also handle
414-
%% notification of test completion. Hmm, maybe test execution
415-
%% should be handled by a `gen_fsm' at this point to distinguish
416-
%% the case when there are tests left to be tried with available
417-
%% resources versus all have been tried or resources are
418-
%% exhausted.
419-
420-
%% [run_test(Test,
421-
%% Outdir,
422-
%% TestMetaData,
423-
%% Report,
424-
%% HarnessArgs,
425-
%% TestCount) ||
426-
%% {Test, TestMetaData} <- Tests],
427-
428-
429-
430387
backend_list(Backend) when is_atom(Backend) ->
431388
atom_to_list(Backend);
432389
backend_list(Backends) when is_list(Backends) ->
@@ -493,3 +450,22 @@ so_kill_riak_maybe() ->
493450
io:format("Leaving Riak Up... "),
494451
rt:whats_up()
495452
end.
453+
454+
%% @doc Start the GiddyUp reporting service if the report is defined
455+
start_giddyup(undefined) ->
456+
ok;
457+
start_giddyup(Platform) ->
458+
{ok, _Pid} = giddyup:start_link(Platform,
459+
rt_config:get_default_version_product(),
460+
rt_config:get_default_version_number(),
461+
rt_config:get_default_version(),
462+
rt_config:get(giddyup_host),
463+
rt_config:get(giddyup_user),
464+
rt_config:get(giddyup_password)).
465+
466+
%% @doc Stop the GiddyUp reporting service if the report is defined
467+
stop_giddyup(true) ->
468+
giddyup:stop();
469+
stop_giddyup(_) ->
470+
ok.
471+

src/rt.erl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
expect_in_log/2,
6464
get_deps/0,
6565
get_ip/1,
66-
get_node_logs/3,
66+
get_node_logs/2,
6767
get_replica/5,
6868
get_ring/1,
6969
get_version/0,
@@ -1078,11 +1078,10 @@ pmap(F, L) ->
10781078
setup_harness(_Test, _Args) ->
10791079
rt_harness:setup().
10801080

1081-
%% @doc Copy all of the nodes' log files to a local dir or
1082-
%% open a port to each file to upload to GiddyUp
1083-
-spec(get_node_logs(boolean(), string(), string()) -> list()).
1084-
get_node_logs(UploadToGiddyUp, LogFile, DestDir) ->
1085-
rt2:get_node_logs(UploadToGiddyUp, LogFile, DestDir).
1081+
%% @doc Copy all of the nodes' log files to a local dir
1082+
-spec(get_node_logs(string(), string()) -> list()).
1083+
get_node_logs(LogFile, DestDir) ->
1084+
rt2:get_node_logs(LogFile, DestDir).
10861085

10871086
check_ibrowse() ->
10881087
rt2:check_ibrowse().

src/rt2.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
expect_in_log/2,
3939
get_deps/0,
4040
get_ip/1,
41-
get_node_logs/3,
41+
get_node_logs/2,
4242
get_replica/5,
4343
get_version/0,
4444
is_mixed_cluster/1,
@@ -610,8 +610,8 @@ setup_harness(Test, Args) ->
610610

611611
%% @doc Downloads any extant log files from the harness's running
612612
%% nodes.
613-
get_node_logs(UploadToGiddyUp, LogFile, DestDir) ->
614-
rt_harness:get_node_logs(UploadToGiddyUp, LogFile, DestDir).
613+
get_node_logs(LogFile, DestDir) ->
614+
rt_harness:get_node_logs(LogFile, DestDir).
615615

616616
check_ibrowse() ->
617617
try sys:get_status(ibrowse) of

src/rt_config.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ get_version(Vsn) ->
178178
resolve_version(Vsn, Versions) ->
179179
case find_atom_or_string(Vsn, Versions) of
180180
undefined ->
181-
erlang:error("Could not find version", [Vsn]);
181+
erlang:error("Could not find Riak version", [Vsn]);
182182
{Product, Tag} ->
183183
convert_to_string(Product) ++ "-" ++ convert_to_string(Tag);
184184
Version ->

src/rt_harness.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
cmd/2,
3838
setup/0,
3939
get_deps/0,
40-
get_node_logs/3,
40+
get_node_logs/2,
4141
get_version/0,
4242
get_version/1,
4343
get_backends/0,
@@ -107,8 +107,8 @@ get_version(Node) ->
107107
get_backends() ->
108108
?HARNESS_MODULE:get_backends().
109109

110-
get_node_logs(UploadToGiddyUp, LogFile, DestDir) ->
111-
?HARNESS_MODULE:get_node_logs(UploadToGiddyUp, LogFile, DestDir).
110+
get_node_logs(LogFile, DestDir) ->
111+
?HARNESS_MODULE:get_node_logs(LogFile, DestDir).
112112

113113
set_backend(Backend) ->
114114
?HARNESS_MODULE:set_backend(Backend).

src/rt_planner.erl

Lines changed: 28 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
%% API
3838
-export([start_link/0,
39-
load_from_giddyup/3,
39+
load_from_giddyup/2,
4040
add_test_plan/5,
4141
fetch_test_plan/0,
4242
fetch_test_non_runnable_plan/0,
@@ -82,19 +82,19 @@ start_link() ->
8282
%%
8383
%% @end
8484
%%--------------------------------------------------------------------
85-
-spec(load_from_giddyup(string(), string() | undefined, list()) -> ok).
86-
load_from_giddyup(Platform, Backend, CommandLineTests) ->
87-
gen_server:call(?MODULE, {load_from_giddyup, Platform, Backend, CommandLineTests}).
85+
-spec(load_from_giddyup([string()] | undefined, list()) -> ok).
86+
load_from_giddyup(Backends, CommandLineTests) ->
87+
gen_server:call(?MODULE, {load_from_giddyup, Backends, CommandLineTests}).
8888

8989
%%--------------------------------------------------------------------
9090
%% @doc
9191
%% Queue up a new test plan
9292
%%
9393
%% @end
9494
%%--------------------------------------------------------------------
95-
-spec(add_test_plan(string(), string(), rt_properties2:storage_backend(), rt_properties2:product_version(), rt_properties2:properties()) -> ok).
96-
add_test_plan(Module, Platform, Backend, Version, Properties) ->
97-
gen_server:call(?MODULE, {add_test_plan, Module, Platform, Backend, Version, Properties}).
95+
-spec(add_test_plan(string(), string(), [string()], rt_properties2:product_version(), rt_properties2:properties()) -> ok).
96+
add_test_plan(Module, Platform, Backends, Version, Properties) ->
97+
gen_server:call(?MODULE, {add_test_plan, Module, Platform, Backends, Version, Properties}).
9898

9999
%%--------------------------------------------------------------------
100100
%% @doc
@@ -185,22 +185,33 @@ init([]) ->
185185
{stop, Reason :: term(), NewState :: #state{}}).
186186
%% Run only those GiddyUp tests which are specified on the command line
187187
%% If none are specified, run everything
188-
handle_call({load_from_giddyup, Platform, _Backend, CommandLineTests}, _From, State) ->
189-
AllGiddyupTests = giddyup:get_suite(Platform),
190-
FilteredTests = case CommandLineTests of
188+
handle_call({load_from_giddyup, Backends, CommandLineTests}, _From, State) ->
189+
AllGiddyupTests = giddyup:get_test_plans(),
190+
FilteredNames = case CommandLineTests of
191191
[] ->
192-
[test_plan_from_giddyup(Test) || Test <- AllGiddyupTests];
192+
AllGiddyupTests;
193193
_ ->
194-
[test_plan_from_giddyup({GName, GMetaData}) || {GName, GMetaData} <- AllGiddyupTests,
195-
CName <- CommandLineTests,
196-
GName =:= CName]
194+
[TestPlan || TestPlan <- AllGiddyupTests,
195+
CName <- CommandLineTests,
196+
rt_test_plan:get_module(TestPlan) =:= CName]
197+
end,
198+
FilteredTests = case Backends of
199+
undefined ->
200+
FilteredNames;
201+
_ ->
202+
[TestPlan || TestPlan <- FilteredNames,
203+
lists:member(rt_test_plan:get(backend, TestPlan), Backends)]
197204
end,
198205
State1 = lists:foldl(fun sort_and_queue/2, State, FilteredTests),
199206
{reply, ok, State1};
200207
%% Add a single test plan to the queue
201-
handle_call({add_test_plan, Module, Platform, Backend, _Version, _Properties}, _From, State) ->
202-
TestPlan = rt_test_plan:new([{module, Module}, {platform, Platform}, {backend, Backend}]),
203-
{reply, ok, sort_and_queue(TestPlan, State)};
208+
handle_call({add_test_plan, Module, Platform, Backends, _Version, _Properties}, _From, State) ->
209+
State1 = lists:foldl(fun(Backend, AccState) ->
210+
TestPlan = rt_test_plan:new([{module, Module}, {platform, Platform}, {backend, Backend}]),
211+
sort_and_queue(TestPlan, AccState)
212+
end,
213+
State, Backends),
214+
{reply, ok, State1};
204215
handle_call(fetch_test_plan, _From, State) ->
205216
Q = State#state.runnable_test_plans,
206217
{Item, Q1} = queue:out(Q),
@@ -291,37 +302,6 @@ code_change(_OldVsn, State, _Extra) ->
291302
%%% Internal functions
292303
%%%===================================================================
293304

294-
%%--------------------------------------------------------------------
295-
%% @private
296-
%% @doc
297-
%% Translate GiddyUp Output into an `rt_test_plan' record
298-
%%
299-
%% @end
300-
%%--------------------------------------------------------------------
301-
302-
-spec(set_giddyup_field(atom(), {proplists:proplist(), rt_test_plan:test_plan()}) -> rt_test_plan:test_plan()).
303-
set_giddyup_field(Field, {MetaData, TestPlan}) ->
304-
{ok, TestPlan1} = case proplists:is_defined(Field, MetaData) of
305-
true ->
306-
rt_test_plan:set(Field, proplists:get_value(Field, MetaData), TestPlan);
307-
_ ->
308-
{ok, TestPlan}
309-
end,
310-
{MetaData, TestPlan1}.
311-
312-
-spec(test_plan_from_giddyup({atom(), term()}) -> rt_test_plan:test_plan()).
313-
test_plan_from_giddyup({Name, MetaData}) ->
314-
Plan0 = rt_test_plan:new([{module, Name}]),
315-
GiddyUpFields = [id, backend, platform, project],
316-
{_, Plan1} = lists:foldl(fun set_giddyup_field/2, {MetaData, Plan0}, GiddyUpFields),
317-
%% Special treatment for the upgrade path
318-
{ok, Plan2} = case proplists:is_defined(upgrade_version, MetaData) of
319-
true ->
320-
rt_test_plan:set(upgrade_path, [rt_config:get_version(proplists:get_value(upgrade_version, MetaData)), rt_config:get_default_version()], Plan1);
321-
_ ->
322-
{ok, Plan1}
323-
end,
324-
Plan2.
325305

326306
%%--------------------------------------------------------------------
327307
%% @private
@@ -350,10 +330,3 @@ is_runnable_test_plan(TestPlan) ->
350330
code:ensure_loaded(Mod),
351331
erlang:function_exported(Mod, Fun, 0) orelse
352332
erlang:function_exported(Mod, Fun, 1).
353-
354-
-ifdef(TEST).
355-
set_giddyup_field_test() ->
356-
S = {#state{runnable_test_plans =queue:new()},[]},
357-
T = test_plan_from_giddyup({test, [{id, 5},{backend,riak_kv_eleveldb_backend}, {platform, "os-x"}, {version, "2.0.5"},{project,<<"riak_ee">>}]}, S),
358-
?assertEqual(T, {#state{runnable_test_plans = {[{rt_test_plan_v1,5,test,<<"riak_ee">>,"os-x",riak_kv_eleveldb_backend,[],undefined}], []}},[]}).
359-
-endif.

0 commit comments

Comments
 (0)