Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/basho_bench.erl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ main(Args) ->

log_dimensions(),

%% Run pre_hook for user code preconditions
run_pre_hook(),

%% Spin up the application
ok = basho_bench_app:start(),

Expand Down Expand Up @@ -176,19 +179,23 @@ test_dir(Opts, Name) ->
wait_for_stop(Mref, infinity) ->
receive
{'DOWN', Mref, _, _, Info} ->
run_post_hook(),
?CONSOLE("Test stopped: ~p\n", [Info])
end;
wait_for_stop(Mref, DurationMins) ->
Duration = timer:minutes(DurationMins) + timer:seconds(1),
receive
{'DOWN', Mref, _, _, Info} ->
run_post_hook(),
?CONSOLE("Test stopped: ~p\n", [Info]);
{shutdown, Reason, Exit} ->
run_post_hook(),
basho_bench_app:stop(),
?CONSOLE("Test shutdown: ~s~n", [Reason]),
halt(Exit)

after Duration ->
run_post_hook(),
basho_bench_app:stop(),
?CONSOLE("Test completed after ~p mins.\n", [DurationMins])
end.
Expand Down Expand Up @@ -255,3 +262,16 @@ load_source_files(Dir) ->
end
end,
filelib:fold_files(Dir, ".*.erl", false, CompileFn, ok).

run_pre_hook() ->
run_hook(basho_bench_config:get(pre_hook, no_op)).

run_post_hook() ->
run_hook(basho_bench_config:get(post_hook, no_op)).

run_hook({Module, Function}) ->
Module:Function();

run_hook(no_op) ->
no_op.

17 changes: 14 additions & 3 deletions src/basho_bench_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ start() ->
NotInc when NotInc == {ok, standalone} orelse NotInc == undefined ->
application:load(sasl),
application:set_env(sasl, sasl_error_logger, {file, "log.sasl.txt"}),
ok = application:start(sasl),

%% Make sure crypto is available
ok = application:start(crypto),
ensure_started([sasl, crypto]),

%% Start up our application -- mark it as permanent so that the node
%% will be killed if we go down
Expand Down Expand Up @@ -95,3 +93,16 @@ stop(_State) ->
%% ===================================================================
%% Internal functions
%% ===================================================================

ensure_started(Applications) when is_list(Applications) ->
[ensure_started(Application) || Application <- Applications];

ensure_started(Application) ->
case application:start(Application) of
ok ->
ok;
{error, {already_started, Application}} ->
ok;
Error ->
throw(Error)
end.