Skip to content

Commit

Permalink
[#113] add stop_sup fuction
Browse files Browse the repository at this point in the history
  • Loading branch information
Euen committed Jul 24, 2017
1 parent 4705e2e commit 4b8c774
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/wpool.erl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
, start_sup_pool/1
, start_sup_pool/2
]).
-export([ stop_sup_pool/1
-export([ stop_pool/1
, stop_sup_pool/1
]).
-export([ call/2
, cast/2
Expand Down Expand Up @@ -136,6 +137,14 @@ start_pool(Name) -> start_pool(Name, []).
{ok, pid()} | {error, {already_started, pid()} | term()}.
start_pool(Name, Options) -> wpool_pool:start_link(Name, all_opts(Options)).

%% @doc Stops the pool
-spec stop_pool(name()) -> true.
stop_pool(Name) ->
case whereis(Name) of
undefined -> true;
Pid -> exit(Pid, normal)
end.

%% @equiv start_sup_pool(Name, [])
-spec start_sup_pool(name()) -> {ok, pid()}.
start_sup_pool(Name) -> start_sup_pool(Name, []).
Expand Down
4 changes: 2 additions & 2 deletions test/wpool_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ overrun(_Config) ->

ok = no_messages(),

ok = wpool:stop_pool(wpool_SUITE_overrun_pool),
ok = wpool:stop_sup_pool(wpool_SUITE_overrun_pool),

{comment, []}.

Expand All @@ -177,7 +177,7 @@ non_brutal_shutdown(_Config) ->
{workers, [{WorkerId, _}]} = lists:keyfind(workers, 1, Stats),
Worker = wpool_pool:worker_name(wpool_SUITE_non_brutal_shutdown, WorkerId),
monitor(process, Worker),
ok = wpool:stop_pool(wpool_SUITE_non_brutal_shutdown),
ok = wpool:stop_sup_pool(wpool_SUITE_non_brutal_shutdown),
receive {'DOWN', _, process, {Worker, _}, Reason} -> shutdown = Reason
after 200 -> ct:fail(worker_not_stopped)
end,
Expand Down
13 changes: 12 additions & 1 deletion test/wpool_pool_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
, init_per_testcase/2
, end_per_testcase/2
]).
-export([ best_worker/1
-export([ stop_worker/1
, best_worker/1
, next_worker/1
, random_worker/1
, available_worker/1
Expand Down Expand Up @@ -79,6 +80,16 @@ wait_and_self(Time) ->
{registered_name, Self} = process_info(self(), registered_name),
Self.

-spec stop_worker(config()) -> {comment, []}.
stop_worker(_Config) ->
true = (undefined /= wpool_pool:find_wpool(stop_worker)),
true = wpool:stop_pool(stop_worker),
timer:sleep(1000),
undefined = wpool_pool:find_wpool(stop_worker),
true = wpool:stop_pool(stop_worker),
undefined = wpool_pool:find_wpool(stop_worker),
{comment, ""}.

-spec available_worker(config()) -> {comment, []}.
available_worker(_Config) ->
Pool = available_worker,
Expand Down

0 comments on commit 4b8c774

Please sign in to comment.