From 545a494ee50325fd75d0993bece7c3a3f14e1280 Mon Sep 17 00:00:00 2001 From: Eugene Neydenov Date: Mon, 22 Aug 2016 21:37:08 +0300 Subject: [PATCH] Call `Application.startup` in GunicornWebWorker - Similar call as done before for `web.run_app` - Extended test case to check `worker.wsgi.startup` has been called once. --- aiohttp/worker.py | 4 +++- tests/test_worker.py | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/aiohttp/worker.py b/aiohttp/worker.py index 607f783daef..7acad99d553 100644 --- a/aiohttp/worker.py +++ b/aiohttp/worker.py @@ -34,7 +34,9 @@ def run(self): self._runner = ensure_future(self._run(), loop=self.loop) try: - self.loop.run_until_complete(self._runner) + self.loop.run_until_complete(asyncio.gather(self._runner, + self.wsgi.startup(), + loop=self.loop)) finally: self.loop.close() diff --git a/tests/test_worker.py b/tests/test_worker.py index 8866215a281..af23d354d2c 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -53,13 +53,17 @@ def test_init_process(worker): def test_run(worker, loop): + worker.wsgi = mock.Mock() + worker.loop = loop worker._run = mock.Mock( wraps=asyncio.coroutine(lambda: None)) + worker.wsgi.startup = mock.Mock( + wraps=asyncio.coroutine(lambda: None)) with pytest.raises(SystemExit): worker.run() - assert worker._run.called + worker.wsgi.startup.assert_called_once_with() assert loop.is_closed()