From 2b2725dddb6e54c3328524e4efa52b544fd77841 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Wed, 23 Jul 2014 07:33:18 +0300 Subject: [PATCH] Support UNIX sockets in gaiohttp worker --- gunicorn/workers/gaiohttp.py | 8 ++++---- tests/test_009-gaiohttp.py | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/gunicorn/workers/gaiohttp.py b/gunicorn/workers/gaiohttp.py index 63c72e9c..199a8025 100644 --- a/gunicorn/workers/gaiohttp.py +++ b/gunicorn/workers/gaiohttp.py @@ -47,7 +47,7 @@ class AiohttpWorker(base.Worker): proto, proto.connection_lost, self.connections, False) return proto - def factory(self, wsgi, host, port): + def factory(self, wsgi, addr): proto = WSGIServerHttpProtocol( wsgi, readpayload=True, loop=self.loop, @@ -58,8 +58,8 @@ class AiohttpWorker(base.Worker): access_log_format=self.cfg.access_log_format) return self.wrap_protocol(proto) - def get_factory(self, sock, host, port): - return functools.partial(self.factory, self.wsgi, host, port) + def get_factory(self, sock, addr): + return functools.partial(self.factory, self.wsgi, addr) @asyncio.coroutine def close(self): @@ -72,7 +72,7 @@ class AiohttpWorker(base.Worker): @asyncio.coroutine def _run(self): for sock in self.sockets: - factory = self.get_factory(sock.sock, *sock.cfg_addr) + factory = self.get_factory(sock.sock, sock.cfg_addr) self.servers.append( (yield from self.loop.create_server(factory, sock=sock.sock))) diff --git a/tests/test_009-gaiohttp.py b/tests/test_009-gaiohttp.py index 843c6cf0..6947fd21 100644 --- a/tests/test_009-gaiohttp.py +++ b/tests/test_009-gaiohttp.py @@ -61,7 +61,7 @@ class WorkerTests(unittest.TestCase): self.worker.cfg = mock.Mock() f = self.worker.factory( - self.worker.wsgi, 'localhost', 8080) + self.worker.wsgi, ('localhost', 8080)) self.assertIsInstance(f, WSGIServerHttpProtocol) @mock.patch('gunicorn.workers.gaiohttp.asyncio') @@ -84,6 +84,26 @@ class WorkerTests(unittest.TestCase): self.assertTrue(self.worker.log.info.called) self.assertTrue(self.worker.notify.called) + @mock.patch('gunicorn.workers.gaiohttp.asyncio') + def test__run_unix_socket(self, m_asyncio): + self.worker.ppid = 1 + self.worker.alive = True + self.worker.servers = [] + sock = mock.Mock() + sock.cfg_addr = '/tmp/gunicorn.sock' + self.worker.sockets = [sock] + self.worker.wsgi = mock.Mock() + self.worker.log = mock.Mock() + self.worker.notify = mock.Mock() + loop = self.worker.loop = mock.Mock() + loop.create_server.return_value = asyncio.Future(loop=self.loop) + loop.create_server.return_value.set_result(sock) + + self.loop.run_until_complete(self.worker._run()) + + self.assertTrue(self.worker.log.info.called) + self.assertTrue(self.worker.notify.called) + def test__run_connections(self): conn = mock.Mock() self.worker.ppid = 1