Skip to content

Commit d6da205

Browse files
authored
Add abort termination logic (#49)
1 parent 35c41f1 commit d6da205

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/basho_bench_duration.erl

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
-export([
1212
run/0,
13-
remaining/0
13+
remaining/0,
14+
abort/1
1415
]).
1516

1617
-export([start_link/0]).
@@ -44,6 +45,10 @@ remaining() ->
4445
gen_server:call(?MODULE, remaining).
4546

4647

48+
abort(Reason) ->
49+
gen_server:cast(?MODULE, {abort, Reason}).
50+
51+
4752
start_link() ->
4853
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
4954

@@ -84,6 +89,9 @@ handle_cast({worker_stopping, WorkerPid}, State) ->
8489
maybe_end({noreply, State})
8590
end;
8691

92+
handle_cast({abort, Reason}, State) ->
93+
{stop, {abort, Reason}, State};
94+
8795
handle_cast(_Msg, State) ->
8896
maybe_end({noreply, State}).
8997

@@ -105,13 +113,19 @@ handle_info(Msg, State) ->
105113

106114

107115
terminate(Reason, #state{duration=DurationMins}) ->
108-
case Reason of
116+
Abort = case Reason of
109117
normal ->
110-
?CONSOLE("Test completed after ~p mins.\n", [DurationMins]);
118+
?CONSOLE("Test completed after ~p mins.\n", [DurationMins]),
119+
false;
111120
{shutdown, normal} ->
112-
?CONSOLE("Test completed after ~p mins.\n", [DurationMins]);
113-
{shutdown, Reason} ->
114-
?CONSOLE("Test stopped: ~p\n", [Reason])
121+
?CONSOLE("Test completed after ~p mins.\n", [DurationMins]),
122+
false;
123+
{shutdown, Reason1} ->
124+
?CONSOLE("Test stopped: ~p\n", [Reason1]),
125+
false;
126+
{abort, Reason1} ->
127+
?CONSOLE("!! Test aborted: ~p\n", [Reason1]),
128+
true
115129
end,
116130
case whereis(basho_bench_worker_sup) of
117131
undefined ->
@@ -126,6 +140,11 @@ terminate(Reason, #state{duration=DurationMins}) ->
126140
end,
127141
run_hook(basho_bench_config:get(post_hook, no_op)),
128142
basho_bench_profiler:maybe_terminate_profiler(basho_bench_config:get(enable_profiler, false)),
143+
if Abort =/= true -> ok; true ->
144+
?CONSOLE("Aborting benchmark run...", []),
145+
timer:sleep(1000),
146+
erlang:halt(1)
147+
end,
129148
supervisor:terminate_child(basho_bench_sup, basho_bench_run_sup),
130149
application:set_env(basho_bench_app, is_running, false),
131150
application:stop(basho_bench),

src/basho_bench_worker.erl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ worker_next_op(State) ->
334334
crash
335335
end;
336336

337+
{abort, Reason} ->
338+
%% Driver signaling stop the world event has occurred.
339+
%% Abort immediately.
340+
?INFO("Driver ~p (~p) has requested abort: ~p\n", [State#state.driver, self(), Reason]),
341+
basho_bench_duration:abort(Reason),
342+
normal;
343+
337344
{stop, Reason} ->
338345
%% Driver (or something within it) has requested that this worker
339346
%% terminate cleanly.

0 commit comments

Comments
 (0)