Skip to content

Commit

Permalink
add test case to eunit
Browse files Browse the repository at this point in the history
  • Loading branch information
uwiger committed Mar 28, 2019
1 parent 8bb81de commit 7adc2a8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/gproc_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ reg_test_() ->
, ?_test(t_is_clean())
, {spawn, ?_test(?debugVal(t_simple_pool()))}
, ?_test(t_is_clean())
, {spawn, ?_test(?debugVal(t_pool_add_worker_race()))}
, ?_test(t_is_clean())
]}.

t_simple_reg() ->
Expand Down Expand Up @@ -1003,6 +1005,30 @@ t_simple_pool()->
%% should be able to delete the pool now
?assertEqual( gproc_pool:delete(p1), ok).

%% verifying #167 - Removing a worker from a pool does not make room
%% for a new worker (size was erroneously adjusted down, though auto_size = false)
t_pool_add_worker_race() ->
ok = gproc_pool:new(p2, direct, [{size, 1}, {auto_size, false}]),
[] = gproc_pool:defined_workers(p2),
Pos1 = gproc_pool:add_worker(p2, worker1),
[{worker1, Pos1, 0}] = gproc_pool:defined_workers(p2),
io:fwrite("G = ~p~n", [ets:tab2list(gproc)]),
Pid = spawn(fun() ->
true = gproc_pool:connect_worker(p2, worker1),
receive after 100 -> bye end
end),
Monitor = monitor(process, Pid),
receive
{'DOWN', Monitor, process, _, _} -> ok
end,
true = gproc_pool:remove_worker(p2, worker1),
[] = gproc_pool:defined_workers(p2), %% the pool seems to be empty
Pos2 = gproc_pool:add_worker(p2, worker2), %% throws error:pool_full
true = is_integer(Pos2),
true = gproc_pool:force_delete(p2).



get_msg() ->
receive M ->
M
Expand Down

0 comments on commit 7adc2a8

Please sign in to comment.