@@ -74,7 +74,7 @@ handle_cast({worker_stopping, WorkerPid}, State) ->
7474 [] ->
7575 ? INFO (" The application has stopped early!" , []),
7676 {stop , {shutdown , normal }, State };
77- _ ->
77+ _ ->
7878 maybe_end ({noreply , State })
7979 end ;
8080
@@ -94,6 +94,12 @@ handle_info(Msg, State) ->
9494
9595
9696terminate (Reason , # state {duration = DurationMins }) ->
97+ case Reason of
98+ {shutdown , normal } ->
99+ ? CONSOLE (" Test completed after ~p mins.\n " , [DurationMins ]);
100+ {shutdown , Reason } ->
101+ ? CONSOLE (" Test stopped: ~p \n " , [Reason ])
102+ end ,
97103 case whereis (basho_bench_worker_sup ) of
98104 undefined ->
99105 ok ;
@@ -108,13 +114,8 @@ terminate(Reason, #state{duration=DurationMins}) ->
108114 run_hook (basho_bench_config :get (post_hook , no_op )),
109115 basho_bench_profiler :maybe_terminate_profiler (basho_bench_config :get (enable_profiler , false )),
110116 supervisor :terminate_child (basho_bench_sup , basho_bench_run_sup ),
111- case Reason of
112- {shutdown , normal } ->
113- ? CONSOLE (" Test completed after ~p mins.\n " , [DurationMins ]);
114- {shutdown , Reason } ->
115- ? CONSOLE (" Test stopped: ~p \n " , [Reason ])
116- end ,
117117 application :set_env (basho_bench_app , is_running , false ),
118+ application :stop (basho_bench ),
118119 ok .
119120
120121
@@ -134,16 +135,20 @@ maybe_end(Return) ->
134135 infinity ->
135136 Return ;
136137 Duration ->
137- case timer :now_diff (os :timestamp (), Start ) of
138- Elapsed when Elapsed / 60000000 >= Duration ->
139- ? CONSOLE (" Stopping: ~p " , [Elapsed ]),
140- {stop , normal , State };
141- Elapsed ->
142- Timeout = round (Duration * 60000 - Elapsed / 1000 ),
143- case tuple_size (Return ) of
144- 2 -> {Reply , State , Timeout };
145- 3 -> {Reply , Message , State , Timeout }
146- end
138+ if Start /= undefined ->
139+ case timer :now_diff (os :timestamp (), Start ) of
140+ Elapsed when Elapsed / 60000000 >= Duration ->
141+ ? CONSOLE (" Stopping: ~p " , [Elapsed ]),
142+ {stop , normal , State };
143+ Elapsed ->
144+ Timeout = round (Duration * 60000 - Elapsed / 1000 ),
145+ case tuple_size (Return ) of
146+ 2 -> {Reply , State , Timeout };
147+ 3 -> {Reply , Message , State , Timeout }
148+ end
149+ end ;
150+ true ->
151+ {Reply , State }
147152 end
148153 end .
149154
0 commit comments