Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix existing tests for device list changes
Browse files Browse the repository at this point in the history
Mainly just adding device list parameters to every method call.
  • Loading branch information
anoadragon453 committed Mar 10, 2022
1 parent 55ac419 commit 3d2f018
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 20 deletions.
48 changes: 33 additions & 15 deletions tests/appservice/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from synapse.logging.context import make_deferred_yieldable
from synapse.server import HomeServer
from synapse.types import DeviceLists
from synapse.util import Clock

from tests import unittest
Expand Down Expand Up @@ -70,6 +71,7 @@ def test_single_service_up_txn_sent(self):
to_device_messages=[], # txn made and saved
one_time_key_counts={},
unused_fallback_keys={},
device_list_summary=DeviceLists(),
)
self.assertEqual(0, len(self.txnctrl.recoverers)) # no recoverer made
txn.complete.assert_called_once_with(self.store) # txn completed
Expand All @@ -96,6 +98,7 @@ def test_single_service_down(self):
to_device_messages=[], # txn made and saved
one_time_key_counts={},
unused_fallback_keys={},
device_list_summary=DeviceLists(),
)
self.assertEqual(0, txn.send.call_count) # txn not sent though
self.assertEqual(0, txn.complete.call_count) # or completed
Expand Down Expand Up @@ -124,6 +127,7 @@ def test_single_service_up_txn_not_sent(self):
to_device_messages=[],
one_time_key_counts={},
unused_fallback_keys={},
device_list_summary=DeviceLists(),
)
self.assertEqual(1, self.recoverer_fn.call_count) # recoverer made
self.assertEqual(1, self.recoverer.recover.call_count) # and invoked
Expand Down Expand Up @@ -225,7 +229,9 @@ def test_send_single_event_no_queue(self):
service = Mock(id=4)
event = Mock()
self.scheduler.enqueue_for_appservice(service, events=[event])
self.txn_ctrl.send.assert_called_once_with(service, [event], [], [], None, None)
self.txn_ctrl.send.assert_called_once_with(
service, [event], [], [], None, None, DeviceLists()
)

def test_send_single_event_with_queue(self):
d = defer.Deferred()
Expand All @@ -240,12 +246,14 @@ def test_send_single_event_with_queue(self):
# (call enqueue_for_appservice multiple times deliberately)
self.scheduler.enqueue_for_appservice(service, events=[event2])
self.scheduler.enqueue_for_appservice(service, events=[event3])
self.txn_ctrl.send.assert_called_with(service, [event], [], [], None, None)
self.txn_ctrl.send.assert_called_with(
service, [event], [], [], None, None, DeviceLists()
)
self.assertEqual(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, [event2, event3], [], [], None, None
service, [event2, event3], [], [], None, None, DeviceLists()
)
self.assertEqual(2, self.txn_ctrl.send.call_count)

Expand All @@ -272,15 +280,21 @@ def do_send(*args, **kwargs):
# send events for different ASes and make sure they are sent
self.scheduler.enqueue_for_appservice(srv1, events=[srv_1_event])
self.scheduler.enqueue_for_appservice(srv1, events=[srv_1_event2])
self.txn_ctrl.send.assert_called_with(srv1, [srv_1_event], [], [], None, None)
self.txn_ctrl.send.assert_called_with(
srv1, [srv_1_event], [], [], None, None, DeviceLists()
)
self.scheduler.enqueue_for_appservice(srv2, events=[srv_2_event])
self.scheduler.enqueue_for_appservice(srv2, events=[srv_2_event2])
self.txn_ctrl.send.assert_called_with(srv2, [srv_2_event], [], [], None, None)
self.txn_ctrl.send.assert_called_with(
srv2, [srv_2_event], [], [], None, None, DeviceLists()
)

# make sure callbacks for a service only send queued events for THAT
# service
srv_2_defer.callback(srv2)
self.txn_ctrl.send.assert_called_with(srv2, [srv_2_event2], [], [], None, None)
self.txn_ctrl.send.assert_called_with(
srv2, [srv_2_event2], [], [], None, None, DeviceLists()
)
self.assertEqual(3, self.txn_ctrl.send.call_count)

def test_send_large_txns(self):
Expand All @@ -300,17 +314,17 @@ def do_send(*args, **kwargs):

# Expect the first event to be sent immediately.
self.txn_ctrl.send.assert_called_with(
service, [event_list[0]], [], [], None, None
service, [event_list[0]], [], [], None, None, DeviceLists()
)
srv_1_defer.callback(service)
# Then send the next 100 events
self.txn_ctrl.send.assert_called_with(
service, event_list[1:101], [], [], None, None
service, event_list[1:101], [], [], None, None, DeviceLists()
)
srv_2_defer.callback(service)
# Then the final 99 events
self.txn_ctrl.send.assert_called_with(
service, event_list[101:], [], [], None, None
service, event_list[101:], [], [], None, None, DeviceLists()
)
self.assertEqual(3, self.txn_ctrl.send.call_count)

Expand All @@ -320,7 +334,7 @@ def test_send_single_ephemeral_no_queue(self):
event_list = [Mock(name="event")]
self.scheduler.enqueue_for_appservice(service, ephemeral=event_list)
self.txn_ctrl.send.assert_called_once_with(
service, [], event_list, [], None, None
service, [], event_list, [], None, None, DeviceLists()
)

def test_send_multiple_ephemeral_no_queue(self):
Expand All @@ -329,7 +343,7 @@ def test_send_multiple_ephemeral_no_queue(self):
event_list = [Mock(name="event1"), Mock(name="event2"), Mock(name="event3")]
self.scheduler.enqueue_for_appservice(service, ephemeral=event_list)
self.txn_ctrl.send.assert_called_once_with(
service, [], event_list, [], None, None
service, [], event_list, [], None, None, DeviceLists()
)

def test_send_single_ephemeral_with_queue(self):
Expand All @@ -345,13 +359,15 @@ def test_send_single_ephemeral_with_queue(self):
# Send more events: expect send() to NOT be called multiple times.
self.scheduler.enqueue_for_appservice(service, ephemeral=event_list_2)
self.scheduler.enqueue_for_appservice(service, ephemeral=event_list_3)
self.txn_ctrl.send.assert_called_with(service, [], event_list_1, [], None, None)
self.txn_ctrl.send.assert_called_with(
service, [], event_list_1, [], None, None, DeviceLists()
)
self.assertEqual(1, self.txn_ctrl.send.call_count)
# Resolve txn_ctrl.send
d.callback(service)
# Expect the queued events to be sent
self.txn_ctrl.send.assert_called_with(
service, [], event_list_2 + event_list_3, [], None, None
service, [], event_list_2 + event_list_3, [], None, None, DeviceLists()
)
self.assertEqual(2, self.txn_ctrl.send.call_count)

Expand All @@ -365,8 +381,10 @@ def test_send_large_txns_ephemeral(self):
event_list = first_chunk + second_chunk
self.scheduler.enqueue_for_appservice(service, ephemeral=event_list)
self.txn_ctrl.send.assert_called_once_with(
service, [], first_chunk, [], None, None
service, [], first_chunk, [], None, None, DeviceLists()
)
d.callback(service)
self.txn_ctrl.send.assert_called_with(service, [], second_chunk, [], None, None)
self.txn_ctrl.send.assert_called_with(
service, [], second_chunk, [], None, None, DeviceLists()
)
self.assertEqual(2, self.txn_ctrl.send.call_count)
11 changes: 10 additions & 1 deletion tests/handlers/test_appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ def test_application_services_receive_local_to_device(self):
to_device_messages,
_otks,
_fbks,
_device_list_summary,
) = self.send_mock.call_args[0]

# Assert that this was the same to-device message that local_user sent
Expand Down Expand Up @@ -583,7 +584,15 @@ def test_application_services_receive_bursts_of_to_device(self):
service_id_to_message_count: Dict[str, int] = {}

for call in self.send_mock.call_args_list:
service, _events, _ephemeral, to_device_messages, _otks, _fbks = call[0]
(
service,
_events,
_ephemeral,
to_device_messages,
_otks,
_fbks,
_device_list_summary,
) = call[0]

# Check that this was made to an interested service
self.assertIn(service, interested_appservices)
Expand Down
17 changes: 13 additions & 4 deletions tests/storage/test_appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
ApplicationServiceStore,
ApplicationServiceTransactionStore,
)
from synapse.types import DeviceLists
from synapse.util import Clock

from tests import unittest
Expand Down Expand Up @@ -267,7 +268,9 @@ def test_create_appservice_txn_first(
events = cast(List[EventBase], [Mock(event_id="e1"), Mock(event_id="e2")])
txn = self.get_success(
defer.ensureDeferred(
self.store.create_appservice_txn(service, events, [], [], {}, {})
self.store.create_appservice_txn(
service, events, [], [], {}, {}, DeviceLists()
)
)
)
self.assertEqual(txn.id, 1)
Expand All @@ -283,7 +286,9 @@ def test_create_appservice_txn_older_last_txn(
self.get_success(self._insert_txn(service.id, 9644, events))
self.get_success(self._insert_txn(service.id, 9645, events))
txn = self.get_success(
self.store.create_appservice_txn(service, events, [], [], {}, {})
self.store.create_appservice_txn(
service, events, [], [], {}, {}, DeviceLists()
)
)
self.assertEqual(txn.id, 9646)
self.assertEqual(txn.events, events)
Expand All @@ -296,7 +301,9 @@ def test_create_appservice_txn_up_to_date_last_txn(
events = cast(List[EventBase], [Mock(event_id="e1"), Mock(event_id="e2")])
self.get_success(self._set_last_txn(service.id, 9643))
txn = self.get_success(
self.store.create_appservice_txn(service, events, [], [], {}, {})
self.store.create_appservice_txn(
service, events, [], [], {}, {}, DeviceLists()
)
)
self.assertEqual(txn.id, 9644)
self.assertEqual(txn.events, events)
Expand All @@ -320,7 +327,9 @@ def test_create_appservice_txn_up_fuzzing(
self.get_success(self._insert_txn(self.as_list[3]["id"], 9643, events))

txn = self.get_success(
self.store.create_appservice_txn(service, events, [], [], {}, {})
self.store.create_appservice_txn(
service, events, [], [], {}, {}, DeviceLists()
)
)
self.assertEqual(txn.id, 9644)
self.assertEqual(txn.events, events)
Expand Down

0 comments on commit 3d2f018

Please sign in to comment.