Skip to content

Commit

Permalink
Async: Immediately start the next read cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuald committed Jun 10, 2016
1 parent 4cdb4eb commit 8825b43
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nsq/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def _read_body(self, data):
self.trigger(event.DATA, conn=self, data=data)
except Exception:
logger.exception('uncaught exception in data event')
self.io_loop.add_callback(self._start_read)
self._start_read()

def send(self, data):
self.stream.write(data)
Expand Down
10 changes: 4 additions & 6 deletions tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,15 @@ def test_read_body():
on_data = create_autospec(f)
conn.on('data', on_data)

mock_ioloop_addcb = create_autospec(f)
mock_io_loop.add_callback = mock_ioloop_addcb
data = 'NSQ'
conn._read_body(data)
on_data.assert_called_once_with(conn=conn, data=data)
mock_ioloop_addcb.assert_called_once_with(conn._start_read)
conn.stream.read_bytes.assert_called_once_with(4, conn._read_size)

# now test functionality when the data_callback fails
on_data.reset_mock()
mock_ioloop_addcb.reset_mock()
conn.stream.read_bytes.reset_mock()
on_data.return_value = Exception("Boom.")
conn._read_body(data)
# verify that we still added callback for the next start_read
mock_ioloop_addcb.assert_called_once_with(conn._start_read)
# verify that the next _start_read was called
conn.stream.read_bytes.assert_called_once_with(4, conn._read_size)

0 comments on commit 8825b43

Please sign in to comment.