Skip to content

Commit

Permalink
Call Application.startup in GunicornWebWorker
Browse files Browse the repository at this point in the history
- Similar call as done before for `web.run_app`
- Extended test case to check `worker.wsgi.startup` has been called once.
  • Loading branch information
f0t0n committed Aug 23, 2016
1 parent ee1532c commit bf708c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion aiohttp/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 5 additions & 1 deletion tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down

0 comments on commit bf708c6

Please sign in to comment.