diff options
author | Will Hunt <will@half-shot.uk> | 2020-10-09 09:49:19 +0100 |
---|---|---|
committer | Will Hunt <will@half-shot.uk> | 2020-10-09 09:49:51 +0100 |
commit | c87401b2299658e9beab68ee7c826e003c440534 (patch) | |
tree | bc7a1b37b65a039c3798cda359d3b65fd6b6eb8b | |
parent | Fix tests (diff) | |
download | synapse-c87401b2299658e9beab68ee7c826e003c440534.tar.xz |
Add new tests
-rw-r--r-- | synapse/appservice/__init__.py | 4 | ||||
-rw-r--r-- | tests/appservice/test_scheduler.py | 37 |
2 files changed, 37 insertions, 4 deletions
diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index ca61d09d84..b3c79a108d 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -196,7 +196,9 @@ class ApplicationService: return True return False - async def is_interested(self, event: EventBase, store: Optional["DataStore"] = None) -> bool: + async def is_interested( + self, event: EventBase, store: Optional["DataStore"] = None + ) -> bool: """Check if this service is interested in this event. Args: diff --git a/tests/appservice/test_scheduler.py b/tests/appservice/test_scheduler.py index a3440b937b..fc47134651 100644 --- a/tests/appservice/test_scheduler.py +++ b/tests/appservice/test_scheduler.py @@ -263,6 +263,37 @@ class ApplicationServiceSchedulerQueuerTestCase(unittest.TestCase): def test_send_single_ephemeral_no_queue(self): # Expect the event to be sent immediately. service = Mock(id=4, name="service") - event = Mock(name="event") - self.queuer.enqueue_ephemeral(service, event) - self.txn_ctrl.send.assert_called_once_with(service, [], event) + event_list = [Mock(name="event")] + self.queuer.enqueue_ephemeral(service, event_list) + self.txn_ctrl.send.assert_called_once_with(service, [], event_list) + + def test_send_multiple_ephemeral_no_queue(self): + # Expect the event to be sent immediately. + service = Mock(id=4, name="service") + event_list = [Mock(name="event1"), Mock(name="event2"), Mock(name="event3")] + self.queuer.enqueue_ephemeral(service, event_list) + self.txn_ctrl.send.assert_called_once_with(service, [], event_list) + + def test_send_single_ephemeral_with_queue(self): + d = defer.Deferred() + self.txn_ctrl.send = Mock( + side_effect=lambda x, y, z: make_deferred_yieldable(d) + ) + service = Mock(id=4) + event_list_1 = [Mock(event_id="event1"), Mock(event_id="event2")] + + # Send more events: expect send() to NOT be called multiple times. + event_list_2 = [Mock(event_id="event3"), Mock(event_id="event4")] + event_list_3 = [Mock(event_id="event5"), Mock(event_id="event6")] + + # Send an event and don't resolve it just yet. + self.queuer.enqueue_ephemeral(service, event_list_1) + + self.queuer.enqueue_ephemeral(service, event_list_2) + self.queuer.enqueue_ephemeral(service, event_list_3) + self.txn_ctrl.send.assert_called_with(service, [], event_list_1) + self.assertEquals(1, self.txn_ctrl.send.call_count) + # Resolve the send event: expect the queued events to be sent + d.callback(service) + self.txn_ctrl.send.assert_called_with(service, [], event_list_2 + event_list_3) + self.assertEquals(2, self.txn_ctrl.send.call_count) |