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

Commit

Permalink
Actually fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Apr 15, 2021
1 parent 7575a68 commit 59d6a01
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
10 changes: 8 additions & 2 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1947,7 +1947,10 @@ def send_presence_to_destinations(
"""

if self._federation:
self._federation.send_presence_to_destinations(states, destinations)
self._federation.send_presence_to_destinations(
states=states,
destinations=destinations,
)

if not self._queue_presence_updates:
return
Expand Down Expand Up @@ -2038,4 +2041,7 @@ async def process_replication_rows(

for host, user_ids in hosts_to_users.items():
states = await self._presence_handler.current_state_for_users(user_ids)
self._federation.send_presence_to_destinations(states.values(), [host])
self._federation.send_presence_to_destinations(
states=states.values(),
destinations=[host],
)
3 changes: 1 addition & 2 deletions synapse/module_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def __init__(self, hs, auth_handler):
self._server_name = hs.hostname
self._presence_stream = hs.get_event_sources().sources["presence"]
self._state = hs.get_state_handler()
self._presence_router = hs.get_presence_router()

self._federation = None
if hs.should_send_federation():
Expand Down Expand Up @@ -442,7 +441,7 @@ async def send_local_online_presence_to(self, users: Iterable[str]) -> None:
# Send to remote destinations
hosts_and_states = await get_interested_remotes(
self._store,
self._presence_router,
self._hs.get_presence_router(),
presence_events,
self._state,
)
Expand Down
17 changes: 9 additions & 8 deletions tests/handlers/test_presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from synapse.api.presence import UserPresenceState
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS
from synapse.events.builder import EventBuilder
from synapse.federation.sender import FederationSender
from synapse.handlers.presence import (
EXTERNAL_PROCESS_EXPIRY,
FEDERATION_PING_INTERVAL,
Expand Down Expand Up @@ -644,10 +645,17 @@ class PresenceJoinTestCase(unittest.HomeserverTestCase):

def make_homeserver(self, reactor, clock):
hs = self.setup_test_homeserver(
"server", federation_http_client=None, federation_sender=Mock()
"server",
federation_http_client=None,
federation_sender=Mock(spec=FederationSender),
)
return hs

def default_config(self):
config = unittest.default_config("test")
config["send_federation"] = True
return config

def prepare(self, reactor, clock, hs):
self.federation_sender = hs.get_federation_sender()
self.event_builder_factory = hs.get_event_builder_factory()
Expand Down Expand Up @@ -691,9 +699,6 @@ def test_remote_joins(self):
# Add a new remote server to the room
self._add_new_user(room_id, "@alice:server2")

# We shouldn't have sent out any local presence *updates*
self.federation_sender.send_presence.assert_not_called()

# When new server is joined we send it the local users presence states.
# We expect to only see user @test2:server, as @test:server is offline
# and has a zero last_active_ts
Expand All @@ -712,7 +717,6 @@ def test_remote_joins(self):
self.federation_sender.reset_mock()
self._add_new_user(room_id, "@bob:server3")

self.federation_sender.send_presence.assert_not_called()
self.federation_sender.send_presence_to_destinations.assert_called_once_with(
destinations=["server3"], states={expected_state}
)
Expand Down Expand Up @@ -757,9 +761,6 @@ def test_remote_gets_presence_when_local_user_joins(self):

self.reactor.pump([0]) # Wait for presence updates to be handled

# We shouldn't have sent out any local presence *updates*
self.federation_sender.send_presence.assert_not_called()

# We expect to only send test2 presence to server2 and server3
expected_state = self.get_success(
self.presence_handler.current_state_for_user("@test2:server")
Expand Down

0 comments on commit 59d6a01

Please sign in to comment.