Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #86 from minus7/subscriber-auth-fix
Browse files Browse the repository at this point in the history
Fix SubscriberProtocol hanging with authentication
  • Loading branch information
fiorix committed Aug 24, 2015
2 parents f086619 + f98f863 commit af5fdab
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions tests/test_subscriber.py
Expand Up @@ -104,3 +104,38 @@ def testPUnsubscribe(self):
self.assertEqual(reply, [u"punsubscribe", u"test_punsubscribe1.*", 1])
reply = yield self.db.punsubscribe("test_punsubscribe2.*")
self.assertEqual(reply, [u"punsubscribe", u"test_punsubscribe2.*", 0])


class TestAuthenticatedSubscriberProtocol(unittest.TestCase):
timeout = 5

@defer.inlineCallbacks
def setUp(self):
meta = yield redis.Connection(REDIS_HOST, REDIS_PORT)
yield meta.execute_command("config", "set", "requirepass", "password")
yield meta.disconnect()
self.addCleanup(self.removePassword)

factory = redis.RedisFactory(None, dbid=0, poolsize=1, password="password")
factory.protocol = redis.SubscriberProtocol
factory.continueTrying = False
reactor.connectTCP(REDIS_HOST, REDIS_PORT, factory)
self.db = yield factory.deferred

@defer.inlineCallbacks
def removePassword(self):
meta = yield redis.Connection(REDIS_HOST, REDIS_PORT, password="password")
yield meta.execute_command("config", "set", "requirepass", "")
yield meta.disconnect()

@defer.inlineCallbacks
def tearDown(self):
yield self.db.disconnect()

@defer.inlineCallbacks
def testSubscribe(self):
reply = yield self.db.subscribe("test_subscribe1")
self.assertEqual(reply, [u"subscribe", u"test_subscribe1", 1])

reply = yield self.db.subscribe("test_subscribe2")
self.assertEqual(reply, [u"subscribe", u"test_subscribe2", 2])
2 changes: 1 addition & 1 deletion txredisapi.py
Expand Up @@ -1711,7 +1711,7 @@ def replyReceived(self, reply):
self.messageReceived(*reply[-3:])
else:
self.replyQueue.put(reply[-3:])
elif isinstance(reply, Exception):
else:
self.replyQueue.put(reply)

def subscribe(self, channels):
Expand Down

0 comments on commit af5fdab

Please sign in to comment.