Common: Only send event to `subscribe_all()` subscribers once

This commit is contained in:
Mike Salvatore 2022-08-10 08:50:32 -04:00
parent 49a28b9161
commit 7bbecc4d3f
2 changed files with 6 additions and 14 deletions

View File

@ -13,14 +13,8 @@ class PyPubSubEventQueue(IEventQueue):
self._pypubsub_publisher = pypubsub_publisher
def subscribe_all(self, subscriber: Callable[[AbstractEvent], None]):
# From the documentation (https://pypubsub.readthedocs.io/en/v4.0.3/usage/
# usage_advanced_debug.html#listen-for-messages-from-all-topics):
# "PyPubSub defines a special topic named pub.ALL_TOPICS. A listener that subscribes
# to this topic will receives all messages of every topic. By default, the listener
# will not receive any data since pub.ALL_TOPICS is the parent of all root topics (...)"
self._pypubsub_publisher.subscribe(
listener=subscriber, topicName=self._pypubsub_publisher.ALL_TOPICS
listener=subscriber, topicName=INTERNAL_ALL_EVENT_TYPES_TOPIC
)
def subscribe_type(

View File

@ -64,18 +64,16 @@ def test_topic_subscription(subscriber_1, subscriber_2, subscriber_1_calls, subs
def test_subscribe_all():
subscriber_calls = []
def subscriber(topic=pub.AUTO_TOPIC):
def subscriber(event, topic=pub.AUTO_TOPIC):
subscriber_calls.append(topic.getName())
pypubsub_event_queue.subscribe_all(subscriber)
pypubsub_event_queue.publish(EventType)
assert subscriber_calls == [
EventType.__name__,
INTERNAL_ALL_EVENT_TYPES_TOPIC,
EVENT_TAG_1,
EVENT_TAG_2,
]
assert len(subscriber_calls) == 1
assert EventType.__name__ not in subscriber_calls
assert EVENT_TAG_1 not in subscriber_calls
assert EVENT_TAG_2 not in subscriber_calls
@pytest.mark.usefixtures("subscriber_1", "subscriber_1_calls")