Default to None if no ephemeral events are ready to be sent

hs/push-reports-to-as
Will Hunt 2020-10-01 17:13:48 +01:00
parent 218e22ae56
commit b8ff93eec7
2 changed files with 8 additions and 8 deletions

View File

@ -135,7 +135,7 @@ class _ServiceQueuer:
)
async def _send_request(
self, service: ApplicationService, ephemeral: Optional[Any] = None
self, service: ApplicationService
):
# sanity-check: we shouldn't get here if this service already has a sender
# running.
@ -145,7 +145,7 @@ class _ServiceQueuer:
try:
while True:
events = self.queued_events.pop(service.id, [])
ephemeral = self.queued_ephemeral.pop(service.id, [])
ephemeral = self.queued_ephemeral.pop(service.id, None)
if not events and not ephemeral:
return
try:

View File

@ -203,7 +203,7 @@ class ApplicationServiceSchedulerQueuerTestCase(unittest.TestCase):
service = Mock(id=4)
event = Mock()
self.queuer.enqueue(service, event)
self.txn_ctrl.send.assert_called_once_with(service, [event])
self.txn_ctrl.send.assert_called_once_with(service, [event], None)
def test_send_single_event_with_queue(self):
d = defer.Deferred()
@ -217,11 +217,11 @@ class ApplicationServiceSchedulerQueuerTestCase(unittest.TestCase):
# Send more events: expect send() to NOT be called multiple times.
self.queuer.enqueue(service, event2)
self.queuer.enqueue(service, event3)
self.txn_ctrl.send.assert_called_with(service, [event])
self.txn_ctrl.send.assert_called_with(service, [event], None)
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, [event2, event3])
self.txn_ctrl.send.assert_called_with(service, [event2, event3], None)
self.assertEquals(2, self.txn_ctrl.send.call_count)
def test_multiple_service_queues(self):
@ -247,13 +247,13 @@ class ApplicationServiceSchedulerQueuerTestCase(unittest.TestCase):
# send events for different ASes and make sure they are sent
self.queuer.enqueue(srv1, srv_1_event)
self.queuer.enqueue(srv1, srv_1_event2)
self.txn_ctrl.send.assert_called_with(srv1, [srv_1_event])
self.txn_ctrl.send.assert_called_with(srv1, [srv_1_event], None)
self.queuer.enqueue(srv2, srv_2_event)
self.queuer.enqueue(srv2, srv_2_event2)
self.txn_ctrl.send.assert_called_with(srv2, [srv_2_event])
self.txn_ctrl.send.assert_called_with(srv2, [srv_2_event], None)
# 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])
self.txn_ctrl.send.assert_called_with(srv2, [srv_2_event2], None)
self.assertEquals(3, self.txn_ctrl.send.call_count)