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

Commit 15c08e5

Browse files
committed
Migrate tests to new way of doing things
1 parent 33702fa commit 15c08e5

File tree

2 files changed

+58
-90
lines changed

2 files changed

+58
-90
lines changed

tests/replication/tcp/test_handler.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2022 The Matrix.org Foundation C.I.C.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from tests.replication._base import BaseMultiWorkerStreamTestCase
16+
from tests.unittest import HomeserverTestCase, override_config
17+
18+
19+
class ChannelsMainTestCase(HomeserverTestCase):
20+
@override_config({"redis": {"enabled": True}})
21+
def test_subscribed_to_enough_redis_channels(self) -> None:
22+
# The default main process is subscribed to USER_IP and all RDATA channels.
23+
self.assertCountEqual(
24+
self.hs.get_replication_command_handler()._channels_to_subscribe_to,
25+
["USER_IP"],
26+
)
27+
28+
29+
class ChannelsWorkerTestCase(BaseMultiWorkerStreamTestCase):
30+
def test_background_worker_subscribed_to_user_ip(self) -> None:
31+
# The default main process is subscribed to USER_IP and all RDATA channels.
32+
worker1 = self.make_worker_hs(
33+
"synapse.app.generic_worker",
34+
extra_config={
35+
"worker_name": "worker1",
36+
"run_background_tasks_on": "worker1",
37+
"redis": {"enabled": True},
38+
},
39+
)
40+
self.assertIn(
41+
"USER_IP",
42+
worker1.get_replication_command_handler()._channels_to_subscribe_to,
43+
)
44+
45+
def test_non_background_worker_not_subscribed_to_user_ip(self) -> None:
46+
# The default main process is subscribed to USER_IP and all RDATA channels.
47+
worker2 = self.make_worker_hs(
48+
"synapse.app.generic_worker",
49+
extra_config={
50+
"worker_name": "worker2",
51+
"run_background_tasks_on": "worker1",
52+
"redis": {"enabled": True},
53+
},
54+
)
55+
self.assertNotIn(
56+
"USER_IP",
57+
worker2.get_replication_command_handler()._channels_to_subscribe_to,
58+
)

tests/replication/tcp/test_redis.py

-90
Original file line numberDiff line numberDiff line change
@@ -11,93 +11,3 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
15-
try:
16-
# We only import it to see if it's installed, so ignore the 'unused' import
17-
import txredisapi # noqa: F401
18-
19-
HAVE_TXREDISAPI = True
20-
except ImportError:
21-
HAVE_TXREDISAPI = False
22-
23-
from tests.replication._base import BaseMultiWorkerStreamTestCase
24-
from tests.unittest import HomeserverTestCase
25-
26-
ALL_RDATA_CHANNELS = [
27-
"RDATA/account_data",
28-
"RDATA/backfill",
29-
"RDATA/caches",
30-
"RDATA/device_lists",
31-
"RDATA/events",
32-
"RDATA/federation",
33-
"RDATA/groups",
34-
"RDATA/presence",
35-
"RDATA/presence_federation",
36-
"RDATA/push_rules",
37-
"RDATA/pushers",
38-
"RDATA/receipts",
39-
"RDATA/tag_account_data",
40-
"RDATA/to_device",
41-
"RDATA/typing",
42-
"RDATA/user_signature",
43-
]
44-
45-
46-
class RedisTestCase(HomeserverTestCase):
47-
if not HAVE_TXREDISAPI:
48-
skip = "Redis extras not installed"
49-
50-
def test_subscribed_to_enough_redis_channels(self) -> None:
51-
from synapse.replication.tcp.redis import RedisDirectTcpReplicationClientFactory
52-
53-
# The default main process is subscribed to USER_IP and all RDATA channels.
54-
self.assertCountEqual(
55-
RedisDirectTcpReplicationClientFactory.channels_to_subscribe_to_for_config(
56-
self.hs.config
57-
),
58-
[
59-
"USER_IP",
60-
]
61-
+ ALL_RDATA_CHANNELS,
62-
)
63-
64-
65-
class RedisWorkerTestCase(BaseMultiWorkerStreamTestCase):
66-
if not HAVE_TXREDISAPI:
67-
skip = "Redis extras not installed"
68-
69-
def test_background_worker_subscribed_to_user_ip(self) -> None:
70-
from synapse.replication.tcp.redis import RedisDirectTcpReplicationClientFactory
71-
72-
# The default main process is subscribed to USER_IP and all RDATA channels.
73-
worker1 = self.make_worker_hs(
74-
"synapse.app.generic_worker",
75-
extra_config={
76-
"worker_name": "worker1",
77-
"run_background_tasks_on": "worker1",
78-
},
79-
)
80-
self.assertIn(
81-
"USER_IP",
82-
RedisDirectTcpReplicationClientFactory.channels_to_subscribe_to_for_config(
83-
worker1.config
84-
),
85-
)
86-
87-
def test_non_background_worker_not_subscribed_to_user_ip(self) -> None:
88-
from synapse.replication.tcp.redis import RedisDirectTcpReplicationClientFactory
89-
90-
# The default main process is subscribed to USER_IP and all RDATA channels.
91-
worker2 = self.make_worker_hs(
92-
"synapse.app.generic_worker",
93-
extra_config={
94-
"worker_name": "worker2",
95-
"run_background_tasks_on": "worker1",
96-
},
97-
)
98-
self.assertNotIn(
99-
"USER_IP",
100-
RedisDirectTcpReplicationClientFactory.channels_to_subscribe_to_for_config(
101-
worker2.config
102-
),
103-
)

0 commit comments

Comments
 (0)