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+
4752start_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+
8795handle_cast (_Msg , State ) ->
8896 maybe_end ({noreply , State }).
8997
@@ -105,13 +113,19 @@ handle_info(Msg, State) ->
105113
106114
107115terminate (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 ),
0 commit comments