Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reply timeout #100

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,34 @@ def setUp(self):
def test_build_ping(self):
s = self._protocol._build_command("PING")
self.assertEqual(s, six.b('*1\r\n$4\r\nPING\r\n'))

class TestRedisFactory(unittest.TestCase):

def setUp(self):
self.timeout = 10
self.clock = task.Clock()
self.trans = StringTransportWithDisconnection()
self.proto = redis.RedisFactory(uuid='foobar',
dbid=None,
poolsize=1,
replyTimeout=self.timeout).buildProtocol(
('127.0.0.1', 0))
self.proto.callLater = self.clock.callLater
self.proto.makeConnection(self.trans)
self.trans.protocol = self.proto

def test_ping(self):
d = self.proto.ping()
d.addCallback(self.assertEqual, 'PONG')
self.proto.dataReceived(six.b('+PONG\r\n'))
return d

def test_connection_lost(self):
d = self.proto.get('foobar')
self.trans.loseConnection()
return self.assertFailure(d, redis.ConnectionError)

def test_reply_timeout(self):
d = self.proto.get('foobar')
self.clock.advance(self.timeout)
return self.assertFailure(d, redis.ConnectionError)
5 changes: 4 additions & 1 deletion txredisapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ def execute_command(self, *args, **kwargs):
raise ConnectionError("Not connected")
else:
command = self._build_command(*args, **kwargs)

# set timeout, reseted in lineReceived()
self.setTimeout(self.factory.replyTimeout)

# When pipelining, buffer this command into our list of
# pipelined commands. Otherwise, write the command immediately.
if self.pipelining:
Expand Down Expand Up @@ -2149,7 +2153,6 @@ def buildProtocol(self, addr):
else:
p = self.protocol()
p.factory = self
p.timeOut = self.replyTimeout
return p

def addConnection(self, conn):
Expand Down