Skip to content

Commit

Permalink
Decrement free_count when replying to queued requestor
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Ferrigni committed Oct 8, 2014
1 parent c57764e commit 2171b10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/pooler.erl
Expand Up @@ -612,15 +612,14 @@ do_return_member(Pid, ok, #pool{name = PoolName,
{ok, {MRef, CPid, _}} ->
#pool{free_pids = Free, in_use_count = NumInUse,
free_count = NumFree} = Pool,
Pool1 = Pool#pool{free_pids = [Pid | Free], in_use_count = NumInUse - 1,
free_count = NumFree + 1},
Pool1 = Pool#pool{in_use_count = NumInUse - 1},
Entry = {MRef, free, os:timestamp()},
Pool2 = Pool1#pool{all_members = store_all_members(Pid, Entry, AllMembers),
consumer_to_pid = cpmap_remove(Pid, CPid,
Pool1#pool.consumer_to_pid)},
case queue:out(QueuedRequestors) of
{empty, _ } ->
Pool2;
Pool2#pool{free_pids = [Pid | Free], free_count = NumFree + 1};
{{value, {From = {APid, _}, TRef}}, NewQueuedRequestors} when is_pid(APid) ->
reply_to_queued_requestor(TRef, Pid, From, NewQueuedRequestors, Pool2)
end;
Expand Down
9 changes: 6 additions & 3 deletions test/pooler_tests.erl
Expand Up @@ -879,7 +879,7 @@ pooler_integration_queueing_return_member_test_() ->
end)
|| _ <- lists:seq(1, (dump_pool(test_pool_1))#pool.max_count)
],
timer:sleep(50),
timer:sleep(1),
Parent = self(),
proc_lib:spawn_link(fun() ->
Val = pooler:take_member(test_pool_1, 200),
Expand All @@ -888,8 +888,11 @@ pooler_integration_queueing_return_member_test_() ->
[Pid ! return || Pid <- Pids],
receive
Result ->
?assert(is_pid(Result))
end
?assert(is_pid(Result)),
pooler:return_member(test_pool_1, Result)
end,
?assertEqual((dump_pool(test_pool_1))#pool.max_count, length((dump_pool(test_pool_1))#pool.free_pids)),
?assertEqual((dump_pool(test_pool_1))#pool.max_count, (dump_pool(test_pool_1))#pool.free_count)
end
end
]
Expand Down

0 comments on commit 2171b10

Please sign in to comment.