From c36df9aeb4255aca90e853038dfe29e4208628a3 Mon Sep 17 00:00:00 2001 From: Eugene Shubin Date: Mon, 20 Apr 2015 17:50:05 +0200 Subject: [PATCH] reproduce worker termination race condition --- test/poolboy_test_worker.erl | 2 ++ test/poolboy_tests.erl | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) 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),