summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarcin Raczyński <niejako@gmail.com>2018-12-17 20:51:04 +0100
committerMarcin Raczyński <niejako@gmail.com>2018-12-17 20:51:04 +0100
commitb5285270b07a56ed92744ca072ebe10fd8ce7d32 (patch)
tree36d3be40c0732eef3496f244acbc6f4a7e2f5de1 /tests
parentf1a1386b5799f5a2f731e25fe3473cb1118d5099 (diff)
downloadredis-py-b5285270b07a56ed92744ca072ebe10fd8ce7d32.tar.gz
Fix #764 - sub-unsub-resub caused PubSub() to forget the channel
Diffstat (limited to 'tests')
-rw-r--r--tests/test_pubsub.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test_pubsub.py b/tests/test_pubsub.py
index 91e9e48..8a8d382 100644
--- a/tests/test_pubsub.py
+++ b/tests/test_pubsub.py
@@ -212,6 +212,46 @@ class TestPubSubSubscribeUnsubscribe(object):
assert message is None
assert p.subscribed is False
+ def test_sub_unsub_resub_channels(self, r):
+ kwargs = make_subscribe_test_data(r.pubsub(), 'channel')
+ self._test_sub_unsub_resub(**kwargs)
+
+ def test_sub_unsub_resub_patterns(self, r):
+ kwargs = make_subscribe_test_data(r.pubsub(), 'pattern')
+ self._test_sub_unsub_resub(**kwargs)
+
+ def _test_sub_unsub_resub(self, p, sub_type, unsub_type, sub_func, unsub_func, keys):
+ # https://github.com/andymccurdy/redis-py/issues/764
+ key = keys[0]
+ sub_func(key)
+ unsub_func(key)
+ sub_func(key)
+ assert p.subscribed is True
+ assert wait_for_message(p) == make_message(sub_type, key, 1)
+ assert wait_for_message(p) == make_message(unsub_type, key, 0)
+ assert wait_for_message(p) == make_message(sub_type, key, 1)
+ assert p.subscribed is True
+
+ def test_sub_unsub_all_resub_channels(self, r):
+ kwargs = make_subscribe_test_data(r.pubsub(), 'channel')
+ self._test_sub_unsub_all_resub(**kwargs)
+
+ def test_sub_unsub_all_resub_patterns(self, r):
+ kwargs = make_subscribe_test_data(r.pubsub(), 'pattern')
+ self._test_sub_unsub_all_resub(**kwargs)
+
+ def _test_sub_unsub_all_resub(self, p, sub_type, unsub_type, sub_func, unsub_func, keys):
+ # https://github.com/andymccurdy/redis-py/issues/764
+ key = keys[0]
+ sub_func(key)
+ unsub_func()
+ sub_func(key)
+ assert p.subscribed is True
+ assert wait_for_message(p) == make_message(sub_type, key, 1)
+ assert wait_for_message(p) == make_message(unsub_type, key, 0)
+ assert wait_for_message(p) == make_message(sub_type, key, 1)
+ assert p.subscribed is True
+
class TestPubSubMessages(object):
def setup_method(self, method):