Skip to content

Commit df56904

Browse files
author
Oliver Ferrigni
committed
Added pre and post hooks
1 parent 7a5decc commit df56904

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/basho_bench.erl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ main(Args) ->
9898

9999
log_dimensions(),
100100

101+
%% Run pre_hook for user code preconditions
102+
run_pre_hook(),
103+
101104
%% Spin up the application
102105
ok = basho_bench_app:start(),
103106

@@ -176,19 +179,23 @@ test_dir(Opts, Name) ->
176179
wait_for_stop(Mref, infinity) ->
177180
receive
178181
{'DOWN', Mref, _, _, Info} ->
182+
run_post_hook(),
179183
?CONSOLE("Test stopped: ~p\n", [Info])
180184
end;
181185
wait_for_stop(Mref, DurationMins) ->
182186
Duration = timer:minutes(DurationMins) + timer:seconds(1),
183187
receive
184188
{'DOWN', Mref, _, _, Info} ->
189+
run_post_hook(),
185190
?CONSOLE("Test stopped: ~p\n", [Info]);
186191
{shutdown, Reason, Exit} ->
192+
run_post_hook(),
187193
basho_bench_app:stop(),
188194
?CONSOLE("Test shutdown: ~s~n", [Reason]),
189195
halt(Exit)
190196

191197
after Duration ->
198+
run_post_hook(),
192199
basho_bench_app:stop(),
193200
?CONSOLE("Test completed after ~p mins.\n", [DurationMins])
194201
end.
@@ -255,3 +262,16 @@ load_source_files(Dir) ->
255262
end
256263
end,
257264
filelib:fold_files(Dir, ".*.erl", false, CompileFn, ok).
265+
266+
run_pre_hook() ->
267+
run_hook(basho_bench_config:get(pre_hook, no_op)).
268+
269+
run_post_hook() ->
270+
run_hook(basho_bench_config:get(post_hook, no_op)).
271+
272+
run_hook({Module, Function}) ->
273+
Module:Function();
274+
275+
run_hook(no_op) ->
276+
no_op.
277+

0 commit comments

Comments
 (0)