Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Aug 23, 2024
1 parent d86146c commit 30fa495
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/wpool_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ complete_coverage(_Config) ->
ct:comment("Queue Manager"),
QMPid = get_queue_manager(PoolPid),
QMPid ! info,
{ok, _} = wpool_queue_manager:start_link(pool, pool_queue_manager),
{ok, _} = wpool_queue_manager:init([{pool, pool}]),

{comment, []}.
Expand Down
28 changes: 28 additions & 0 deletions test/wpool_pool_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ best_worker(_Config) ->
ok
end,

Req = wpool:send_request(Pool, {erlang, self, []}, best_worker),
{reply, {ok, _}} = gen_server:wait_response(Req, 5000),

%% Fill up their message queues...
[wpool:cast(Pool, {timer, sleep, [60000]}, next_worker) || _ <- lists:seq(1, ?WORKERS)],
[0] = ktn_task:wait_for(fun() -> worker_msg_queue_lengths(Pool) end, [0]),
Expand Down Expand Up @@ -208,6 +211,9 @@ next_available_worker(_Config) ->
ct:log("Wait until the first frees up..."),
1 = ktn_task:wait_for(AvailableWorkers, 1),

Req = wpool:send_request(Pool, {erlang, self, []}, next_available_worker),
{reply, {ok, _}} = gen_server:wait_response(Req, 5000),

ok = wpool:cast(Pool, {timer, sleep, [60000]}, next_available_worker),

ct:log("No more available workers..."),
Expand Down Expand Up @@ -243,6 +249,7 @@ next_worker(_Config) ->
?WORKERS =
sets:size(
sets:from_list(Res0)),

Res0 =
[begin
Stats = wpool:stats(Pool),
Expand All @@ -251,6 +258,9 @@ next_worker(_Config) ->
end
|| I <- lists:seq(1, ?WORKERS)],

Req = wpool:send_request(Pool, {erlang, self, []}, next_worker),
{reply, {ok, _}} = gen_server:wait_response(Req, 5000),

{comment, []}.

-spec random_worker(config()) -> {comment, []}.
Expand All @@ -273,6 +283,21 @@ random_worker(_Config) ->
sets:size(
sets:from_list(Serial)),

%% Randomly ask a lot of workers to send ourselves the atom true
[wpool:cast(Pool, {erlang, send, [self(), true]}, random_worker)
|| _ <- lists:seq(1, 20 * ?WORKERS)],
Results =
[receive
true ->
true
end
|| _ <- lists:seq(1, 20 * ?WORKERS)],
true = lists:all(fun(Value) -> true =:= Value end, Results),

%% do a gen_server:send_request/3
Req = wpool:send_request(Pool, {erlang, self, []}, random_worker),
{reply, {ok, _}} = gen_server:wait_response(Req, 5000),

%% Now do the same with a freshly spawned process for each request to ensure
%% randomness isn't reset with each spawn of the process_dictionary
Self = self(),
Expand Down Expand Up @@ -365,6 +390,9 @@ custom_worker(_Config) ->
end
|| I <- lists:seq(1, ?WORKERS)],

Req = wpool:send_request(Pool, {erlang, self, []}, Strategy),
{reply, {ok, _}} = gen_server:wait_response(Req, 5000),

{comment, []}.

-spec manager_crash(config()) -> {comment, []}.
Expand Down

0 comments on commit 30fa495

Please sign in to comment.