diff options
author | Marcin Raczyński <niejako@gmail.com> | 2018-12-17 20:51:04 +0100 |
---|---|---|
committer | Marcin Raczyński <niejako@gmail.com> | 2018-12-17 20:51:04 +0100 |
commit | b5285270b07a56ed92744ca072ebe10fd8ce7d32 (patch) | |
tree | 36d3be40c0732eef3496f244acbc6f4a7e2f5de1 /tests | |
parent | f1a1386b5799f5a2f731e25fe3473cb1118d5099 (diff) | |
download | redis-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.py | 40 |
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): |