devinus/poolboy — pull request #15 by Vagabond (2012-08-31 15:58:44+00:00)
Title: Update quickcheck to use blocking/1 and fix uncovered bug

Blocking/1 was added in quickcheck 1.27 and allows the test to indicate
which states might block execution and lets quickcheck find bugs around
them.

The bug uncovered has to do with when a process holding a worker exits,
the DOWN monitor fires and poolboy calls supervisor:terminate_child on
the worker the process held. When the EXIT message comes in for that
process, we then change the state around such that there is an
additional worker.

This caused a race condition if there were already checkout messages
waiting in the mailbox, because the EXIT message would come in behind
the checkout messages, and so even though we had just killed a worker,
we'd fail checkouts because we hadn't processed the EXIT yet.

The fix is to call into handle_worker_exit right after we terminate the
worker, thus updating our state to reflect the actual worker count
before processing any messages in the mailbox.