|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # 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