diff options
| author | Jeffrey Yasskin <jyasskin@gmail.com> | 2008-02-28 18:03:15 (GMT) |
|---|---|---|
| committer | Jeffrey Yasskin <jyasskin@gmail.com> | 2008-02-28 18:03:15 (GMT) |
| commit | 392c159ad6a0a622c5d78b6783039e836829a6d9 (patch) | |
| tree | 2febe0ccd983074bcb4cc7700b268e2ea61070aa /Lib/test/test_socketserver.py | |
| parent | a6298528e1f5c10abd0d4255ef911179e9b1b912 (diff) | |
| download | cpython-392c159ad6a0a622c5d78b6783039e836829a6d9.zip cpython-392c159ad6a0a622c5d78b6783039e836829a6d9.tar.gz cpython-392c159ad6a0a622c5d78b6783039e836829a6d9.tar.bz2 | |
Prevent SocketServer.ForkingMixIn from waiting on child processes that it
didn't create, in most cases. When there are max_children handlers running, it
will still wait for any child process, not just handler processes.
Diffstat (limited to 'Lib/test/test_socketserver.py')
| -rw-r--r-- | Lib/test/test_socketserver.py | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py index 4a70e59..98a4c1f 100644 --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -2,6 +2,7 @@ Test suite for SocketServer.py. """ +import contextlib import errno import imp import os @@ -82,6 +83,18 @@ class ServerThread(threading.Thread): if verbose: print "thread: done" +@contextlib.contextmanager +def simple_subprocess(testcase): + pid = os.fork() + if pid == 0: + # Don't throw an exception; it would be caught by the test harness. + os._exit(72) + yield None + pid2, status = os.waitpid(pid, 0) + testcase.assertEquals(pid2, pid) + testcase.assertEquals(72 << 8, status) + + class SocketServerTest(unittest.TestCase): """Test all socket servers.""" @@ -183,10 +196,11 @@ class SocketServerTest(unittest.TestCase): self.stream_examine) if HAVE_FORKING: - def test_ThreadingTCPServer(self): - self.run_server(SocketServer.ForkingTCPServer, - SocketServer.StreamRequestHandler, - self.stream_examine) + def test_ForkingTCPServer(self): + with simple_subprocess(self): + self.run_server(SocketServer.ForkingTCPServer, + SocketServer.StreamRequestHandler, + self.stream_examine) if HAVE_UNIX_SOCKETS: def test_UnixStreamServer(self): @@ -201,9 +215,10 @@ class SocketServerTest(unittest.TestCase): if HAVE_FORKING: def test_ForkingUnixStreamServer(self): - self.run_server(ForkingUnixStreamServer, - SocketServer.StreamRequestHandler, - self.stream_examine) + with simple_subprocess(self): + self.run_server(ForkingUnixStreamServer, + SocketServer.StreamRequestHandler, + self.stream_examine) def test_UDPServer(self): self.run_server(SocketServer.UDPServer, @@ -217,9 +232,10 @@ class SocketServerTest(unittest.TestCase): if HAVE_FORKING: def test_ForkingUDPServer(self): - self.run_server(SocketServer.ForkingUDPServer, - SocketServer.DatagramRequestHandler, - self.dgram_examine) + with simple_subprocess(self): + self.run_server(SocketServer.ForkingUDPServer, + SocketServer.DatagramRequestHandler, + self.dgram_examine) # Alas, on Linux (at least) recvfrom() doesn't return a meaningful # client address so this cannot work: |
