From 874f9d240bea6595141ae7dee3b9e9f40ca83478 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 8 Dec 2018 12:30:47 +0000 Subject: [PATCH] Test multiple subscribers --- ipc_unix/pubsub.py | 2 +- tests/test_pubsub.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ipc_unix/pubsub.py b/ipc_unix/pubsub.py index d05ee85..1bae3cf 100644 --- a/ipc_unix/pubsub.py +++ b/ipc_unix/pubsub.py @@ -47,7 +47,7 @@ class Publisher: self.connections.clear() def accept_new_connection(self): - if socket_has_data(self.master_socket): + while socket_has_data(self.master_socket): new_socket, _ = self.master_socket.accept() self.connections.append(new_socket) diff --git a/tests/test_pubsub.py b/tests/test_pubsub.py index be3b83e..9f2dc72 100644 --- a/tests/test_pubsub.py +++ b/tests/test_pubsub.py @@ -29,3 +29,10 @@ class PubSubTestCase(TestCase): all_messages = self.subscriber.flush_data() message_ids = [message["data"] for message in all_messages] self.assertEqual(message_ids, [0, 1, 2, 3, 4]) + + def test_multiple_subscribers(self): + subscriber_2 = pubsub.Subscriber(self.socket_path) + self.publisher.write({"foo": "bar"}) + self.assertEqual(self.subscriber.get_latest_message(), {"foo": "bar"}) + self.assertEqual(subscriber_2.get_latest_message(), {"foo": "bar"}) + subscriber_2.close()