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

Commit

Permalink
Fixup functions to consistently return deferreds
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Dec 6, 2019
1 parent b2ee65e commit b3a4e35
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
6 changes: 3 additions & 3 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ async def ephemeral_by_room(self, sync_result_builder, now_token, since_token=No
room_ids = sync_result_builder.joined_room_ids

typing_source = self.event_sources.sources["typing"]
typing, typing_key = typing_source.get_new_events(
typing, typing_key = await typing_source.get_new_events(
user=sync_config.user,
from_key=typing_key,
limit=sync_config.filter_collection.ephemeral_limit(),
Expand Down Expand Up @@ -1013,7 +1013,7 @@ async def _generate_sync_entry_for_groups(self, sync_result_builder):
now_token = sync_result_builder.now_token

if since_token and since_token.groups_key:
results = self.store.get_groups_changes_for_user(
results = await self.store.get_groups_changes_for_user(
user_id, since_token.groups_key, now_token.groups_key
)
else:
Expand Down Expand Up @@ -1197,7 +1197,7 @@ async def _generate_sync_entry_for_account_data(self, sync_result_builder):
(
account_data,
account_data_by_room,
) = self.store.get_updated_account_data_for_user(
) = await self.store.get_updated_account_data_for_user(
user_id, since_token.account_data_key
)

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def get_new_events(self, from_key, room_ids, **kwargs):

events.append(self._make_event_for(room_id))

return events, handler._latest_room_serial
return defer.succeed((events, handler._latest_room_serial))

def get_current_key(self):
return self.get_typing_handler()._latest_room_serial
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/data_stores/main/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def get_updated_account_data_for_user_txn(txn):
user_id, int(stream_id)
)
if not changed:
return {}, {}
return defer.succeed(({}, {}))

return self.runInteraction(
"get_updated_account_data_for_user", get_updated_account_data_for_user_txn
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/data_stores/main/group_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ def get_groups_changes_for_user(self, user_id, from_token, to_token):
user_id, from_token
)
if not has_changed:
return []
return defer.succeed([])

def _get_groups_changes_for_user_txn(txn):
sql = """
Expand Down Expand Up @@ -1139,7 +1139,7 @@ def get_all_groups_changes(self, from_token, to_token, limit):
from_token
)
if not has_changed:
return []
return defer.succeed([])

def _get_all_groups_changes_txn(txn):
sql = """
Expand Down
24 changes: 18 additions & 6 deletions tests/handlers/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def test_started_typing_local(self):
self.on_new_event.assert_has_calls([call("typing_key", 1, rooms=[ROOM_ID])])

self.assertEquals(self.event_source.get_current_key(), 1)
events = self.event_source.get_new_events(room_ids=[ROOM_ID], from_key=0)
events = self.get_success(
self.event_source.get_new_events(room_ids=[ROOM_ID], from_key=0)
)
self.assertEquals(
events[0],
[
Expand Down Expand Up @@ -227,7 +229,9 @@ def test_started_typing_remote_recv(self):
self.on_new_event.assert_has_calls([call("typing_key", 1, rooms=[ROOM_ID])])

self.assertEquals(self.event_source.get_current_key(), 1)
events = self.event_source.get_new_events(room_ids=[ROOM_ID], from_key=0)
events = self.get_success(
self.event_source.get_new_events(room_ids=[ROOM_ID], from_key=0)
)
self.assertEquals(
events[0],
[
Expand Down Expand Up @@ -279,7 +283,9 @@ def test_stopped_typing(self):
)

self.assertEquals(self.event_source.get_current_key(), 1)
events = self.event_source.get_new_events(room_ids=[ROOM_ID], from_key=0)
events = self.get_success(
self.event_source.get_new_events(room_ids=[ROOM_ID], from_key=0)
)
self.assertEquals(
events[0],
[{"type": "m.typing", "room_id": ROOM_ID, "content": {"user_ids": []}}],
Expand All @@ -300,7 +306,9 @@ def test_typing_timeout(self):
self.on_new_event.reset_mock()

self.assertEquals(self.event_source.get_current_key(), 1)
events = self.event_source.get_new_events(room_ids=[ROOM_ID], from_key=0)
events = self.get_success(
self.event_source.get_new_events(room_ids=[ROOM_ID], from_key=0)
)
self.assertEquals(
events[0],
[
Expand All @@ -317,7 +325,9 @@ def test_typing_timeout(self):
self.on_new_event.assert_has_calls([call("typing_key", 2, rooms=[ROOM_ID])])

self.assertEquals(self.event_source.get_current_key(), 2)
events = self.event_source.get_new_events(room_ids=[ROOM_ID], from_key=1)
events = self.get_success(
self.event_source.get_new_events(room_ids=[ROOM_ID], from_key=1)
)
self.assertEquals(
events[0],
[{"type": "m.typing", "room_id": ROOM_ID, "content": {"user_ids": []}}],
Expand All @@ -335,7 +345,9 @@ def test_typing_timeout(self):
self.on_new_event.reset_mock()

self.assertEquals(self.event_source.get_current_key(), 3)
events = self.event_source.get_new_events(room_ids=[ROOM_ID], from_key=0)
events = self.get_success(
self.event_source.get_new_events(room_ids=[ROOM_ID], from_key=0)
)
self.assertEquals(
events[0],
[
Expand Down
4 changes: 3 additions & 1 deletion tests/rest/client/v1/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def test_set_typing(self):
self.assertEquals(200, channel.code)

self.assertEquals(self.event_source.get_current_key(), 1)
events = self.event_source.get_new_events(from_key=0, room_ids=[self.room_id])
events = self.get_success(
self.event_source.get_new_events(from_key=0, room_ids=[self.room_id])
)
self.assertEquals(
events[0],
[
Expand Down

0 comments on commit b3a4e35

Please sign in to comment.