Test multiple subscribers

This commit is contained in:
Jake Howard 2018-12-08 12:30:47 +00:00
parent c7af71456e
commit 874f9d240b
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 8 additions and 1 deletions

View file

@ -47,7 +47,7 @@ class Publisher:
self.connections.clear() self.connections.clear()
def accept_new_connection(self): 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() new_socket, _ = self.master_socket.accept()
self.connections.append(new_socket) self.connections.append(new_socket)

View file

@ -29,3 +29,10 @@ class PubSubTestCase(TestCase):
all_messages = self.subscriber.flush_data() all_messages = self.subscriber.flush_data()
message_ids = [message["data"] for message in all_messages] message_ids = [message["data"] for message in all_messages]
self.assertEqual(message_ids, [0, 1, 2, 3, 4]) 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()