diff --git a/test/poolboy_test_worker.erl b/test/poolboy_test_worker.erl index 8be523b..bc34ea1 100644 --- a/test/poolboy_test_worker.erl +++ b/test/poolboy_test_worker.erl @@ -17,6 +17,8 @@ handle_call(die, _From, State) -> handle_call(_Event, _From, State) -> {reply, ok, State}. +handle_cast(die, State) -> + {stop, {error, died}, State}; handle_cast(_Event, State) -> {noreply, State}. diff --git a/test/poolboy_tests.erl b/test/poolboy_tests.erl index b0f3b39..26b52a3 100644 --- a/test/poolboy_tests.erl +++ b/test/poolboy_tests.erl @@ -72,7 +72,9 @@ pool_test_() -> {<<"Recover from timeout without exit handling">>, fun transaction_timeout_without_exit/0}, {<<"Recover from transaction timeout">>, - fun transaction_timeout/0} + fun transaction_timeout/0}, + {<<"Worker death synchronisation">>, + fun async_worker_death/0} ] }. @@ -92,6 +94,26 @@ checkin_worker(Pid, Worker) -> poolboy:checkin(Pid, Worker), timer:sleep(500). +async_worker_death() -> + {ok, Pid} = new_pool(1, 0), + ?assertEqual( + ok, + poolboy:transaction( + Pid, + fun(Worker) -> + gen_server:cast(Worker, die) + end) + ), + ?assertEqual( + ok, + poolboy:transaction( + Pid, + fun(Worker) -> + pool_call(Worker, check) + end) + ). + + transaction_timeout_without_exit() -> {ok, Pid} = new_pool(1, 0),