Skip to content

Commit

Permalink
Merge pull request #114 from inaka/euen.113.sync_names_of_start_stop_…
Browse files Browse the repository at this point in the history
…functions

Euen.113.sync names of start stop functions
  • Loading branch information
elbrujohalcon authored Jul 24, 2017
2 parents 5870947 + 4b8c774 commit 0734821
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
17 changes: 15 additions & 2 deletions src/wpool.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
-module(wpool).
-author('[email protected]').





-define(DEFAULTS, [ {overrun_warning, infinity}
, {overrun_handler, {error_logger, warning_report}}
, {workers, 100}, {worker_opt, []}
Expand Down Expand Up @@ -83,6 +87,7 @@
, start_sup_pool/2
]).
-export([ stop_pool/1
, stop_sup_pool/1
]).
-export([ call/2
, cast/2
Expand Down Expand Up @@ -132,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 All @@ -143,8 +156,8 @@ start_sup_pool(Name, Options) ->
wpool_sup:start_pool(Name, all_opts(Options)).

%% @doc Stops the pool
-spec stop_pool(name()) -> ok.
stop_pool(Name) -> wpool_sup:stop_pool(Name).
-spec stop_sup_pool(name()) -> ok.
stop_sup_pool(Name) -> wpool_sup:stop_pool(Name).

%% @doc Default strategy
-spec default_strategy() -> strategy().
Expand Down
12 changes: 6 additions & 6 deletions test/wpool_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ too_much_overrun(_Config) ->
ok = no_messages(),

ct:comment("Stop pool..."),
ok = wpool:stop_pool(wpool_SUITE_too_much_overrun),
ok = wpool:stop_sup_pool(wpool_SUITE_too_much_overrun),

{comment, []}.

Expand Down Expand Up @@ -153,17 +153,17 @@ overrun(_Config) ->

ok = no_messages(),

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

{comment, []}.

-spec stop_pool(config()) -> {comment, []}.
stop_pool(_Config) ->
{ok, PoolPid} = wpool:start_sup_pool(wpool_SUITE_stop_pool, [{workers, 1}]),
true = erlang:is_process_alive(PoolPid),
ok = wpool:stop_pool(wpool_SUITE_stop_pool),
ok = wpool:stop_sup_pool(wpool_SUITE_stop_pool),
false = erlang:is_process_alive(PoolPid),
ok = wpool:stop_pool(wpool_SUITE_stop_pool),
ok = wpool:stop_sup_pool(wpool_SUITE_stop_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 Expand Up @@ -241,7 +241,7 @@ stats(_Config) ->
true = is_number(Get(runtime, WorkerStats))
end || I <- lists:seq(1, 10)],

wpool:stop_pool(wpool_SUITE_stats_pool),
wpool:stop_sup_pool(wpool_SUITE_stats_pool),

timer:sleep(5000),

Expand Down
2 changes: 1 addition & 1 deletion test/wpool_bench.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ run_tasks(TaskGroups, Strategy, Options) ->
error_logger:info_msg("Times: ~p", [Times]),
lists:sum(Times) / length(Times)
after
wpool:stop_pool(?MODULE)
wpool:stop_sup_pool(?MODULE)
end.

run_task(small, Strategy, Acc) ->
Expand Down
15 changes: 13 additions & 2 deletions 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 @@ -70,7 +71,7 @@ init_per_testcase(TestCase, Config) ->

-spec end_per_testcase(atom(), config()) -> config().
end_per_testcase(TestCase, Config) ->
catch wpool:stop_pool(TestCase),
catch wpool:stop_sup_pool(TestCase),
Config.

-spec wait_and_self(pos_integer()) -> pid().
Expand All @@ -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
4 changes: 2 additions & 2 deletions test/wpool_worker_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ call(_Config) ->
exit:?MODULE -> ok
end,
{error, invalid_request} = wpool:call(?MODULE, error),
ok = wpool:stop_pool(?MODULE),
ok = wpool:stop_sup_pool(?MODULE),

{comment, []}.

Expand All @@ -63,7 +63,7 @@ cast(_Config) ->
ok = wpool_worker:cast(?MODULE, ?MODULE, error, []),
ok = wpool:cast(?MODULE, x),
timer:sleep(1000),
ok = wpool:stop_pool(?MODULE),
ok = wpool:stop_sup_pool(?MODULE),

{comment, []}.

Expand Down

0 comments on commit 0734821

Please sign in to comment.