diff --git a/src/basho_bench.erl b/src/basho_bench.erl index 4fe6fb3cd..5fe45b928 100644 --- a/src/basho_bench.erl +++ b/src/basho_bench.erl @@ -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(), @@ -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. @@ -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. + diff --git a/src/basho_bench_app.erl b/src/basho_bench_app.erl index 499356869..3ec50fa12 100644 --- a/src/basho_bench_app.erl +++ b/src/basho_bench_app.erl @@ -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 @@ -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.