Pylons/waitress — pull request #35 by kgaughan (2013-05-28 02:29:52+00:00)
Title: Switch from using the subprocess module for running functional test fixtures to using multiprocessing

There are two changesets in this pull request.

The first is incidental and alters how Unix socket support is detected to make it a little more robust: it checks for the presence of 'AF_UNIX' in the socket module. The docs for the socket module state that this is a safe way to check that if the platform supports Unix sockets.

The second one switches functional test fixture server execution from using the subprocess module to using the multiprocess module. I did this as I'd occasionally have tests fail due to race conditions whereby a fixture would not be in a position to accept connections before a test attempted to connect to it. This was particularly an issue with PyPy, as it's somewhat slower to start up than CPython.

Instead, the fixtures are spun up as separate processes using the multiprocessing module. When a server is ready to accept connections, it uses a queue to (a) signal this and (b) return the address/path it's bound to. This solves the race condition issue, and also fixes another issue where occasionally a fixture would end up using a port already in use by another process.

As this eliminates the need to use sleeps to avoid races, it has the side effect of making the whole test suite run twelve times faster.