diff options
author | Abhimanyu Deora <abhikdeora@gmail.com> | 2020-10-26 11:16:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-26 09:16:23 -0700 |
commit | a404ad3dee93b3b0deb90b4075fd28734d78a282 (patch) | |
tree | a9d9e83a2fc9b12419a03246ccce3f8210f6f87e /tests/test_pubsub.py | |
parent | 15dafb1414f05ce24ef336fc539e06ad6a2b3d19 (diff) | |
download | redis-py-a404ad3dee93b3b0deb90b4075fd28734d78a282.tar.gz |
Add optional exception handler to PubSubWorkerThread (#1395)
Add optional exception handler to PubSubWorkerThread
Co-authored-by: Abhimanyu Deora <adeora@drwholdings.com>
Diffstat (limited to 'tests/test_pubsub.py')
-rw-r--r-- | tests/test_pubsub.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_pubsub.py b/tests/test_pubsub.py index ab9f09c..abeaecb 100644 --- a/tests/test_pubsub.py +++ b/tests/test_pubsub.py @@ -1,6 +1,9 @@ import pytest +import threading import time +from unittest import mock + import redis from redis.exceptions import ConnectionError @@ -543,3 +546,24 @@ class TestPubSubTimeouts: p.subscribe('foo') assert wait_for_message(p) == make_message('subscribe', 'foo', 1) assert p.get_message(timeout=0.01) is None + + +class TestPubSubWorkerThread: + def test_pubsub_worker_thread_exception_handler(self, r): + event = threading.Event() + + def exception_handler(ex, pubsub, thread): + thread.stop() + event.set() + + p = r.pubsub() + p.subscribe(**{'foo': lambda m: m}) + with mock.patch.object(p, 'get_message', + side_effect=Exception('error')): + pubsub_thread = p.run_in_thread( + exception_handler=exception_handler + ) + + assert event.wait(timeout=1.0) + pubsub_thread.join(timeout=1.0) + assert not pubsub_thread.is_alive() |