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

Update unit tests configuration settings #14568

Merged
merged 24 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a89ec04
Adjust tests with legacy settings for sending federation to use moder…
realtyem Nov 27, 2022
8e99103
Adjust tests with legacy settings involving pushers to modern settings.
realtyem Nov 27, 2022
2b972a5
Linting found a whoops.
realtyem Nov 27, 2022
0dafd0f
Add explicit override.
realtyem Nov 27, 2022
eab6536
Replace 'synapse.app.client_reader' with 'synapse.app.generic_worker'…
realtyem Nov 28, 2022
b57aeb1
Update tests using 'update_user_directory'.
realtyem Nov 28, 2022
44ec2eb
Changelog
realtyem Nov 28, 2022
b00d88f
Per review, update how 'update_user_directory_from_worker' is used to…
realtyem Nov 29, 2022
91195d3
Per review, consolidate overridden settings into a 'default_config()'…
realtyem Nov 29, 2022
0abc6cc
Per review, consolidate override into a 'default_config()' and add do…
realtyem Nov 29, 2022
c37364d
Remove now unused import
realtyem Nov 29, 2022
b9f765d
Shorten a bunch of wordy comments.
realtyem Nov 29, 2022
26c7bec
Per review, consolidate override into a 'default_config()' and add do…
realtyem Nov 29, 2022
e7138f2
Per review, remove redundant 'default_config()'s that served no purpo…
realtyem Nov 29, 2022
71623f0
Per review, change all 'sender's to 'federation_sender's.
realtyem Nov 29, 2022
8bde002
Remove more unused imports.
realtyem Nov 29, 2022
2c1a0a0
Per review, fix up a bunch of things I did weird/wrong. And remove th…
realtyem Nov 29, 2022
9cb0a6f
Update tests/replication/test_federation_ack.py
realtyem Nov 29, 2022
b2e4590
Give the last worker a name.
realtyem Nov 29, 2022
a1a848f
Merge branch 'develop' into fix-tests-generic-workers
realtyem Nov 29, 2022
6de8d5a
Remove outdated comment.
clokep Nov 30, 2022
9ab160f
Tweak comment / name of user dir worker.
clokep Nov 30, 2022
62ff49e
Clarify changelog.
clokep Nov 30, 2022
b3025ad
Merge branch 'develop' into fix-tests-generic-workers
clokep Nov 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/14568.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update some unit tests configuration that are related to workers.
clokep marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 16 additions & 4 deletions tests/events/test_presence_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ def prepare(self, reactor, clock, homeserver):
},
}
},
"send_federation": True,
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
"federation_sender_instances": None,
realtyem marked this conversation as resolved.
Show resolved Hide resolved
}
)
def test_receiving_all_presence_legacy(self):
Expand All @@ -180,7 +183,10 @@ def test_receiving_all_presence_legacy(self):
},
},
],
"send_federation": True,
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
"federation_sender_instances": None,
}
)
def test_receiving_all_presence(self):
Expand Down Expand Up @@ -290,7 +296,10 @@ def receiving_all_presence_test_body(self):
},
}
},
"send_federation": True,
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
"federation_sender_instances": None,
}
)
def test_send_local_online_presence_to_with_module_legacy(self):
Expand All @@ -310,7 +319,10 @@ def test_send_local_online_presence_to_with_module_legacy(self):
},
},
],
"send_federation": True,
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
"federation_sender_instances": None,
}
)
def test_send_local_online_presence_to_with_module(self):
Expand Down
30 changes: 24 additions & 6 deletions tests/federation/test_federation_catch_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def get_destination_room(self, room: str, destination: str = "host2") -> dict:
)[0]
return {"event_id": event_id, "stream_ordering": stream_ordering}

@override_config({"send_federation": True})
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
@override_config({"federation_sender_instances": None})
def test_catch_up_destination_rooms_tracking(self):
"""
Tests that we populate the `destination_rooms` table as needed.
Expand All @@ -105,7 +108,10 @@ def test_catch_up_destination_rooms_tracking(self):
self.assertEqual(row_2["event_id"], event_id_2)
self.assertEqual(row_1["stream_ordering"], row_2["stream_ordering"] - 1)

@override_config({"send_federation": True})
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
@override_config({"federation_sender_instances": None})
def test_catch_up_last_successful_stream_ordering_tracking(self):
"""
Tests that we populate the `destination_rooms` table as needed.
Expand Down Expand Up @@ -163,7 +169,10 @@ def test_catch_up_last_successful_stream_ordering_tracking(self):
"Send succeeded but not marked as last_successful_stream_ordering",
)

@override_config({"send_federation": True}) # critical to federate
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
@override_config({"federation_sender_instances": None}) # critical to federate
def test_catch_up_from_blank_state(self):
"""
Runs an overall test of federation catch-up from scratch.
Expand Down Expand Up @@ -260,7 +269,10 @@ async def fake_send(

return per_dest_queue, results_list

@override_config({"send_federation": True})
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
@override_config({"federation_sender_instances": None})
def test_catch_up_loop(self):
"""
Tests the behaviour of _catch_up_transmission_loop.
Expand Down Expand Up @@ -325,7 +337,10 @@ def test_catch_up_loop(self):
event_5.internal_metadata.stream_ordering,
)

@override_config({"send_federation": True})
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
@override_config({"federation_sender_instances": None})
def test_catch_up_on_synapse_startup(self):
"""
Tests the behaviour of get_catch_up_outstanding_destinations and
Expand Down Expand Up @@ -424,7 +439,10 @@ def wake_destination_track(destination):
# - all destinations are woken exactly once; they appear once in woken.
self.assertCountEqual(woken, server_names[:-1])

@override_config({"send_federation": True})
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
@override_config({"federation_sender_instances": None})
def test_not_latest_event(self):
"""Test that we send the latest event in the room even if its not ours."""

Expand Down
15 changes: 12 additions & 3 deletions tests/federation/test_federation_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def make_homeserver(self, reactor, clock):

return hs

@override_config({"send_federation": True})
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
@override_config({"federation_sender_instances": None})
def test_send_receipts(self):
mock_send_transaction = (
self.hs.get_federation_transport_client().send_transaction
Expand Down Expand Up @@ -83,7 +86,10 @@ def test_send_receipts(self):
],
)

@override_config({"send_federation": True})
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
@override_config({"federation_sender_instances": None})
def test_send_receipts_with_backoff(self):
"""Send two receipts in quick succession; the second should be flushed, but
only after 20ms"""
Expand Down Expand Up @@ -184,7 +190,10 @@ def make_homeserver(self, reactor, clock):

def default_config(self):
c = super().default_config()
c["send_federation"] = True
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
c["federation_sender_instances"] = None
return c

def prepare(self, reactor, clock, hs):
Expand Down
5 changes: 4 additions & 1 deletion tests/handlers/test_presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,10 @@ def make_homeserver(self, reactor, clock):

def default_config(self):
config = super().default_config()
config["send_federation"] = True
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
config["federation_sender_instances"] = None
return config

def prepare(self, reactor, clock, hs):
Expand Down
10 changes: 8 additions & 2 deletions tests/handlers/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ def test_started_typing_local(self) -> None:
],
)

@override_config({"send_federation": True})
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
@override_config({"federation_sender_instances": None})
def test_started_typing_remote_send(self) -> None:
self.room_members = [U_APPLE, U_ONION]

Expand Down Expand Up @@ -305,7 +308,10 @@ def test_started_typing_remote_recv_not_in_room(self) -> None:
self.assertEqual(events[0], [])
self.assertEqual(events[1], 0)

@override_config({"send_federation": True})
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
@override_config({"federation_sender_instances": None})
def test_stopped_typing(self) -> None:
self.room_members = [U_APPLE, U_BANANA, U_ONION]

Expand Down
8 changes: 6 additions & 2 deletions tests/handlers/test_user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase):

def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
config = self.default_config()
config["update_user_directory"] = True
# Remove the value that disables updating the user directory, as that function
# is needed below.
config.pop("update_user_directory_from_worker")

self.appservice = ApplicationService(
token="i_am_an_app_service",
Expand Down Expand Up @@ -1045,7 +1047,9 @@ class TestUserDirSearchDisabled(unittest.HomeserverTestCase):

def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
config = self.default_config()
config["update_user_directory"] = True
# Remove the value that disables updating the user directory, as that function
# is needed below. It will be force disabled later
config.pop("update_user_directory_from_worker")
realtyem marked this conversation as resolved.
Show resolved Hide resolved
hs = self.setup_test_homeserver(config=config)

self.config = hs.config
Expand Down
5 changes: 4 additions & 1 deletion tests/module_api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ def test_send_local_online_presence_to(self):
# Test sending local online presence to users from the main process
_test_sending_local_online_presence_to_local_user(self, test_with_workers=False)

@override_config({"send_federation": True})
# Default test case disables federation sending. Setting
# 'federation_sender_instances' to None turns it back on for the main
# process
@override_config({"federation_sender_instances": None})
realtyem marked this conversation as resolved.
Show resolved Hide resolved
def test_send_local_online_presence_to_federation(self):
"""Tests that send_local_presence_to_users sends local online presence to remote users."""
# Create a user who will send presence updates
Expand Down
1 change: 0 additions & 1 deletion tests/push/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def make_homeserver(self, reactor, clock):
"riot_base_url": None,
}
config["public_baseurl"] = "http://aaa"
config["start_pushers"] = True

hs = self.setup_test_homeserver(config=config)

Expand Down
1 change: 0 additions & 1 deletion tests/push/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class HTTPPusherTests(HomeserverTestCase):

def default_config(self) -> Dict[str, Any]:
config = super().default_config()
config["start_pushers"] = True
realtyem marked this conversation as resolved.
Show resolved Hide resolved
return config

def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
Expand Down
2 changes: 1 addition & 1 deletion tests/replication/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def make_worker_hs(
stream to the master HS.

Args:
worker_app: Type of worker, e.g. `synapse.app.federation_sender`.
worker_app: Type of worker, e.g. `synapse.app.generic_worker`.
extra_config: Any extra config to use for this instances.
**kwargs: Options that get passed to `self.setup_test_homeserver`,
useful to e.g. pass some mocks for things like `federation_http_client`
Expand Down
6 changes: 3 additions & 3 deletions tests/replication/tcp/streams/test_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class FederationStreamTestCase(BaseStreamTestCase):
def _get_worker_hs_config(self) -> dict:
# enable federation sending on the worker
config = super()._get_worker_hs_config()
# TODO: make it so we don't need both of these
config["send_federation"] = False
config["worker_app"] = "synapse.app.federation_sender"
# The 'worker_app' is declared to be 'synapse.app.generic_worker' in super()
clokep marked this conversation as resolved.
Show resolved Hide resolved
# Workers with no name default to whatever is in the 'worker_app'
realtyem marked this conversation as resolved.
Show resolved Hide resolved
config["federation_sender_instances"] = ["synapse.app.generic_worker"]
return config

def test_catchup(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/replication/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def make_homeserver(self, reactor, clock):

def _get_worker_hs_config(self) -> dict:
config = self.default_config()
config["worker_app"] = "synapse.app.client_reader"
config["worker_app"] = "synapse.app.generic_worker"
config["worker_replication_host"] = "testserv"
config["worker_replication_http_port"] = "8765"

Expand All @@ -53,7 +53,7 @@ def _test_register(self) -> FakeChannel:
4. Return the final request.

"""
worker_hs = self.make_worker_hs("synapse.app.client_reader")
worker_hs = self.make_worker_hs("synapse.app.generic_worker")
site = self._hs_to_site[worker_hs]

channel_1 = make_request(
Expand Down
14 changes: 7 additions & 7 deletions tests/replication/test_client_reader_shard.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@


class ClientReaderTestCase(BaseMultiWorkerStreamTestCase):
"""Test using one or more client readers for registration."""
"""Test using one or more generic workers for registration."""

servlets = [register.register_servlets]

def _get_worker_hs_config(self) -> dict:
config = self.default_config()
config["worker_app"] = "synapse.app.client_reader"
config["worker_app"] = "synapse.app.generic_worker"
config["worker_replication_host"] = "testserv"
config["worker_replication_http_port"] = "8765"
return config

def test_register_single_worker(self):
"""Test that registration works when using a single client reader worker."""
worker_hs = self.make_worker_hs("synapse.app.client_reader")
"""Test that registration works when using a single generic worker."""
worker_hs = self.make_worker_hs("synapse.app.generic_worker")
site = self._hs_to_site[worker_hs]

channel_1 = make_request(
Expand Down Expand Up @@ -64,9 +64,9 @@ def test_register_single_worker(self):
self.assertEqual(channel_2.json_body["user_id"], "@user:test")

def test_register_multi_worker(self):
"""Test that registration works when using multiple client reader workers."""
worker_hs_1 = self.make_worker_hs("synapse.app.client_reader")
worker_hs_2 = self.make_worker_hs("synapse.app.client_reader")
"""Test that registration works when using multiple generic workers."""
worker_hs_1 = self.make_worker_hs("synapse.app.generic_worker")
worker_hs_2 = self.make_worker_hs("synapse.app.generic_worker")

site_1 = self._hs_to_site[worker_hs_1]
channel_1 = make_request(
Expand Down
5 changes: 3 additions & 2 deletions tests/replication/test_federation_ack.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
class FederationAckTestCase(HomeserverTestCase):
def default_config(self) -> dict:
config = super().default_config()
config["worker_app"] = "synapse.app.federation_sender"
config["send_federation"] = False
config["worker_app"] = "synapse.app.generic_worker"
# Workers with no name default to whatever is in 'worker_app'
config["federation_sender_instances"] = ["synapse.app.generic_worker"]
realtyem marked this conversation as resolved.
Show resolved Hide resolved
return config

def make_homeserver(self, reactor, clock):
Expand Down
Loading