Skip to content

Commit

Permalink
Fix #172: Set server.transport to None on .closing()
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Nov 12, 2014
1 parent dad995f commit a6fe3ed
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CHANGES

- Drop closed connections from connector #173

- Set server.transport to None on .closing() #172

0.9.3 (10-30-2014)
------------------

Expand Down
1 change: 1 addition & 0 deletions aiohttp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def closing(self):
if ((not self._reading_request or self._request_handler is None) and
self.transport is not None):
self.transport.close()
self.transport = None

def connection_made(self, transport):
super().connection_made(transport)
Expand Down
31 changes: 29 additions & 2 deletions tests/test_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,38 @@ def test_closing(self):
srv._keep_alive_handle = keep_alive_handle
timeout_handle = unittest.mock.Mock()
srv._timeout_handle = timeout_handle
srv.transport = unittest.mock.Mock()
transport = srv.transport = unittest.mock.Mock()
srv.writer = unittest.mock.Mock()

srv.closing()
self.assertTrue(srv.transport.close.called)
self.assertTrue(transport.close.called)
self.assertIsNone(srv.transport)

self.assertIsNotNone(srv._keep_alive_handle)
self.assertFalse(keep_alive_handle.cancel.called)

self.assertIsNotNone(srv._timeout_handle)
self.assertFalse(timeout_handle.cancel.called)

def test_double_closing(self):
srv = server.ServerHttpProtocol(loop=self.loop)
srv._keep_alive = True

keep_alive_handle = unittest.mock.Mock()
srv._keep_alive_handle = keep_alive_handle
timeout_handle = unittest.mock.Mock()
srv._timeout_handle = timeout_handle
transport = srv.transport = unittest.mock.Mock()
srv.writer = unittest.mock.Mock()

srv.closing()
self.assertTrue(transport.close.called)
self.assertIsNone(srv.transport)

transport.reset_mock()
srv.closing()
self.assertFalse(transport.close.called)
self.assertIsNone(srv.transport)

self.assertIsNotNone(srv._keep_alive_handle)
self.assertFalse(keep_alive_handle.cancel.called)
Expand Down

0 comments on commit a6fe3ed

Please sign in to comment.