mperham/connection_pool — pull request #3 by ryanlecompte (2012-02-06 04:00:20+00:00)
Title: Fix for race condition (issue #2)

I was able to reproduce the failing test on both 1.9.3 and 1.9.2 using:

rake TESTOPTS="--seed=50855"

After a bit of debugging, it turns out that the test in its current form could yield different results depending on which threads the thread manager decides to run. NetworkConnection#do_something has an explicit sleep, which signals to Ruby that it can execute another thread. Therefore, the order in which the threads execute/complete is not deterministic across test runs - you can see this by printing out when each thread completes in the block passed to ConnectionPool#with_connection.

Sorting the final result to be compared fixes the problem for me!