Permalink
Browse files

Fix wrong status

  • Loading branch information...
1 parent 771b423 commit c73c97a80caf82dad86e065f3f71e370aabe091b @ddosia ddosia committed Dec 2, 2012
Showing with 40 additions and 10 deletions.
  1. +15 −9 src/poolboy.erl
  2. +25 −1 test/poolboy_tests.erl
View
@@ -150,15 +150,9 @@ handle_call({checkout, Block, Timeout}, {FromPid, _} = From, State) ->
handle_call(status, _From, State) ->
#state{workers = Workers,
monitors = Monitors,
- overflow = Overflow,
- max_overflow = MaxOverflow} = State,
- WorkersLen = queue:len(Workers),
- StateName = case WorkersLen == 0 of
- true when MaxOverflow < 1 -> full;
- true -> overflow;
- false -> ready
- end,
- {reply, {StateName, WorkersLen, Overflow, ets:info(Monitors, size)}, State};
+ overflow = Overflow} = State,
+ StateName = state_name(State),
+ {reply, {StateName, queue:len(Workers), Overflow, ets:info(Monitors, size)}, State};
handle_call(get_avail_workers, _From, State) ->
Workers = State#state.workers,
WorkerList = queue:to_list(Workers),
@@ -311,3 +305,15 @@ handle_worker_exit(Pid, State) ->
),
State#state{workers = Workers, waiting = Empty}
end.
+
+state_name(State = #state{overflow = Overflow}) when Overflow < 1 ->
+ #state{max_overflow = MaxOverflow, workers = Workers} = State,
+ case queue:len(Workers) == 0 of
+ true when MaxOverflow < 1 -> full;
+ true -> overflow;
+ false -> ready
+ end;
+state_name(#state{overflow = MaxOverflow, max_overflow = MaxOverflow}) ->
+ full;
+state_name(_State) ->
+ overflow.
View
@@ -369,7 +369,31 @@ checkin_after_exception_in_transaction() ->
pool_returns_status() ->
{ok, Pool} = new_pool(2, 0),
?assertEqual({ready, 2, 0, 0}, poolboy:status(Pool)),
- ok = ?sync(Pool, stop).
+ poolboy:checkout(Pool),
+ ?assertEqual({ready, 1, 0, 1}, poolboy:status(Pool)),
+ poolboy:checkout(Pool),
+ ?assertEqual({full, 0, 0, 2}, poolboy:status(Pool)),
+ ok = ?sync(Pool, stop),
+
+ {ok, Pool2} = new_pool(1, 1),
+ ?assertEqual({ready, 1, 0, 0}, poolboy:status(Pool2)),
+ poolboy:checkout(Pool2),
+ ?assertEqual({overflow, 0, 0, 1}, poolboy:status(Pool2)),
+ poolboy:checkout(Pool2),
+ ?assertEqual({full, 0, 1, 2}, poolboy:status(Pool2)),
+ ok = ?sync(Pool2, stop),
+
+ {ok, Pool3} = new_pool(0, 2),
+ ?assertEqual({overflow, 0, 0, 0}, poolboy:status(Pool3)),
+ poolboy:checkout(Pool3),
+ ?assertEqual({overflow, 0, 1, 1}, poolboy:status(Pool3)),
+ poolboy:checkout(Pool3),
+ ?assertEqual({full, 0, 2, 2}, poolboy:status(Pool3)),
+ ok = ?sync(Pool3, stop),
+
+ {ok, Pool4} = new_pool(0, 0),
+ ?assertEqual({full, 0, 0, 0}, poolboy:status(Pool4)),
+ ok = ?sync(Pool4, stop).
new_pool(Size, MaxOverflow) ->
poolboy:start_link([{name, {local, poolboy_test}},

0 comments on commit c73c97a

Please sign in to comment.