Skip to content

Commit 7edbe91

Browse files
author
Brett Hazen
committed
Fix specification of backends
- Default backend in rt_planner is now undefined - All lists of backends are now atoms - Command-line limits backends when using GiddyUp - Command-line now properly generates multiple tests when a list of backends is specified
1 parent d3975f6 commit 7edbe91

File tree

5 files changed

+77
-16
lines changed

5 files changed

+77
-16
lines changed

src/giddyup.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ fetch_all_test_plans(Platform, Product, VersionNumber, DefaultVersion, Host) ->
267267
Module = binary_to_atom(kvc:path(name, Test), utf8),
268268
Plan0 = rt_test_plan:new([{id, Id}, {module, Module}, {project, Project}, {platform, Platform}, {version, VersionNumber}]),
269269
{ok, Plan1} = case kvc:path('tags.backend', Test) of
270-
[] -> {ok, Plan0};
270+
%% Bitcask is the default version
271+
[] -> rt_test_plan:set(backend, bitcask, Plan0);
271272
Backend -> rt_test_plan:set(backend, binary_to_atom(Backend, utf8), Plan0)
272273
end,
273274
{ok, Plan2} = case kvc:path('tags.upgrade_version', Test) of

src/riak_test_escript.erl

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
-export([main/1]).
2626
-export([add_deps/1]).
2727

28+
-ifdef(TEST).
29+
-include_lib("eunit/include/eunit.hrl").
30+
-endif.
31+
2832
main(Args) ->
2933
%% TODO Should we use clique? -jsb
3034
%% Parse command line arguments ...
@@ -104,12 +108,25 @@ generate_test_lists(UseGiddyUp, ParsedArgs) ->
104108
%% test metadata
105109

106110
TestData = compose_test_data(ParsedArgs),
107-
Backends = [proplists:get_value(backend, ParsedArgs, bitcask)],
111+
CmdLineBackends = rt_util:backend_to_atom_list(proplists:get_value(backend, ParsedArgs)),
112+
Backends = determine_backends(CmdLineBackends, UseGiddyUp),
108113
{Tests, NonTests} = wrap_test_in_test_plan(UseGiddyUp, Backends, TestData),
109114
Offset = rt_config:get(offset, undefined),
110115
Workers = rt_config:get(workers, undefined),
111116
shuffle_tests(Tests, NonTests, Offset, Workers).
112117

118+
%% @doc Which backends should be tested?
119+
%% Use the command-line specified backend, otherwise default to bitcask
120+
%% If running under GiddyUp, then default to ALL backends
121+
%% First argument is a list of command-line backends and second is whether or not in GiddyUp mode
122+
-spec(determine_backends(atom(), boolean()) -> list()).
123+
determine_backends(undefined, true) ->
124+
[memory, bitcask, eleveldb];
125+
determine_backends(undefined, _) ->
126+
[bitcask];
127+
determine_backends(Backends, _) ->
128+
Backends.
129+
113130
%% @doc Set values in the configuration with values specified on the command line
114131
maybe_override_setting(Argument, Value, Arguments) ->
115132
maybe_override_setting(proplists:is_defined(Argument, Arguments), Argument,
@@ -385,16 +402,6 @@ match_group_attributes(Attributes, Groups) ->
385402
|| Group <- Groups, TestType <- TestTypes ])
386403
end.
387404

388-
backend_list(Backend) when is_atom(Backend) ->
389-
atom_to_list(Backend);
390-
backend_list(Backends) when is_list(Backends) ->
391-
FoldFun = fun(X, []) ->
392-
atom_to_list(X);
393-
(X, Acc) ->
394-
Acc ++ "," ++ atom_to_list(X)
395-
end,
396-
lists:foldl(FoldFun, [], Backends).
397-
398405
load_tests_in_dir(Dir, Groups, SkipTests) ->
399406
case filelib:is_dir(Dir) of
400407
true ->
@@ -470,3 +477,19 @@ stop_giddyup(true) ->
470477
stop_giddyup(_) ->
471478
ok.
472479

480+
-ifdef(TEST).
481+
%% Make sure that bitcask is the default backend
482+
default_backend_test() ->
483+
?assertEqual([bitcask], determine_backends(undefined, false)).
484+
485+
%% Make sure that GiddyUp supports all backends
486+
default_giddyup_backend_test() ->
487+
?assertEqual([bitcask, eleveldb, memory], lists:sort(determine_backends(undefined, true))).
488+
489+
%% Command-line backends should always rule
490+
cmdline_backend_test() ->
491+
?assertEqual([memory], determine_backends([memory], false)),
492+
?assertEqual([memory], determine_backends([memory], true)),
493+
?assertEqual([eleveldb, memory], lists:sort(determine_backends([memory, eleveldb], false))),
494+
?assertEqual([eleveldb, memory], lists:sort(determine_backends([memory, eleveldb], true))).
495+
-endif.

src/rt_planner.erl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ load_from_giddyup(Backends, CommandLineTests) ->
9292
%%
9393
%% @end
9494
%%--------------------------------------------------------------------
95-
-spec(add_test_plan(string(), string(), [string()], rt_properties2:product_version(), rt_properties2:properties()) -> ok).
95+
-spec(add_test_plan(string(), string(), [atom()], rt_properties2:product_version(), rt_properties2:properties()) -> ok).
9696
add_test_plan(Module, Platform, Backends, Version, Properties) ->
9797
gen_server:call(?MODULE, {add_test_plan, Module, Platform, Backends, Version, Properties}).
9898

@@ -183,7 +183,8 @@ init([]) ->
183183
{noreply, NewState :: #state{}, timeout() | hibernate} |
184184
{stop, Reason :: term(), Reply :: term(), NewState :: #state{}} |
185185
{stop, Reason :: term(), NewState :: #state{}}).
186-
%% Run only those GiddyUp tests which are specified on the command line
186+
%% Run only those GiddyUp tests which are specified on the command line and are
187+
%% included in the specified backends.
187188
%% If none are specified, run everything
188189
handle_call({load_from_giddyup, Backends, CommandLineTests}, _From, State) ->
189190
AllGiddyupTests = giddyup:get_test_plans(),
@@ -207,7 +208,7 @@ handle_call({load_from_giddyup, Backends, CommandLineTests}, _From, State) ->
207208
State1 = lists:foldl(fun sort_and_queue/2, State, Included1),
208209
State2 = lists:foldl(fun exclude_test_plan/2, State1, Excluded1),
209210
{reply, ok, State2};
210-
%% Add a single test plan to the queue
211+
%% Add a single test plan for each backend to the queue
211212
handle_call({add_test_plan, Module, Platform, Backends, _Version, _Properties}, _From, State) ->
212213
State1 = lists:foldl(fun(Backend, AccState) ->
213214
TestPlan = rt_test_plan:new([{module, Module}, {platform, Platform}, {backend, Backend}]),
@@ -326,6 +327,7 @@ sort_and_queue(TestPlan, State) ->
326327
non_runnable_test_plans=QNR2}.
327328

328329
%% Check for api compatibility
330+
%% TODO: Move into "harness" or "driver" since it might be on a remote node.
329331
is_runnable_test_plan(TestPlan) ->
330332
TestModule = rt_test_plan:get_module(TestPlan),
331333
{Mod, Fun} = riak_test_runner:function_name(confirm, TestModule),

src/rt_test_plan.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
project=rt_config:get_default_version_product() :: atom() | binary(),
4343
platform :: string(),
4444
version=rt_config:get_default_version_number() :: string(),
45-
backend=bitcask :: atom(),
45+
backend=undefined :: atom(),
4646
upgrade_path=[] :: [rt_properties2:product_version()],
4747
properties :: rt_properties2:properties()
4848
}).

src/rt_util.erl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,38 @@
55

66
-export_type([error/0,
77
result/0]).
8+
-export([backend_to_atom_list/1]).
9+
10+
-ifdef(TEST).
11+
-include_lib("eunit/include/eunit.hrl").
12+
-endif.
13+
14+
%% @doc Convert string or atom to list of atoms
15+
-spec(backend_to_atom_list(atom()|string()) -> undefined | list()).
16+
backend_to_atom_list(undefined) ->
17+
undefined;
18+
backend_to_atom_list(Backends) when is_atom(Backends) ->
19+
ListBackends = atom_to_list(Backends),
20+
case lists:member($, , ListBackends) of
21+
true ->
22+
[list_to_atom(X) || X <- string:tokens(ListBackends, ", ")];
23+
_ ->
24+
[Backends]
25+
end;
26+
backend_to_atom_list(Backends) when is_list(Backends) ->
27+
case lists:member($, , Backends) of
28+
true ->
29+
[list_to_atom(X) || X <- string:tokens(Backends, ", ")];
30+
_ ->
31+
[list_to_atom(Backends)]
32+
end.
33+
34+
-ifdef(TEST).
35+
%% Properly covert backends to atoms
36+
backend_to_atom_list_test() ->
37+
?assertEqual(undefined, backend_to_atom_list(undefined)),
38+
?assertEqual([memory], backend_to_atom_list(memory)),
39+
?assertEqual([memory], backend_to_atom_list("memory")),
40+
?assertEqual([bitcask, eleveldb, memory], lists:sort(backend_to_atom_list("memory, bitcask,eleveldb"))),
41+
?assertEqual([bitcask, eleveldb, memory], lists:sort(backend_to_atom_list('memory, bitcask,eleveldb'))).
42+
-endif.

0 commit comments

Comments
 (0)