|
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 | | -from typing import Optional |
| 14 | +from typing import Any, Mapping, Optional |
15 | 15 | from unittest.mock import Mock |
16 | 16 |
|
| 17 | +from frozendict import frozendict |
| 18 | + |
17 | 19 | from synapse.config import ConfigError |
18 | 20 | from synapse.config.workers import WorkerConfig |
19 | 21 |
|
20 | 22 | from tests.unittest import TestCase |
21 | 23 |
|
| 24 | +_EMPTY_FROZENDICT: Mapping[str, Any] = frozendict() |
| 25 | + |
22 | 26 |
|
23 | 27 | class WorkerDutyConfigTestCase(TestCase): |
24 | 28 | def _make_worker_config( |
25 | | - self, worker_app: str, worker_name: Optional[str] |
| 29 | + self, |
| 30 | + worker_app: str, |
| 31 | + worker_name: Optional[str], |
| 32 | + extras: Mapping[str, Any] = _EMPTY_FROZENDICT, |
26 | 33 | ) -> WorkerConfig: |
27 | 34 | root_config = Mock() |
28 | 35 | root_config.worker_app = worker_app |
29 | 36 | root_config.worker_name = worker_name |
30 | 37 | worker_config = WorkerConfig(root_config) |
31 | | - worker_config.read_config( |
32 | | - {"worker_name": worker_name, "worker_app": worker_app} |
33 | | - ) |
| 38 | + worker_config_dict = { |
| 39 | + "worker_name": worker_name, |
| 40 | + "worker_app": worker_app, |
| 41 | + **extras, |
| 42 | + } |
| 43 | + worker_config.read_config(worker_config_dict) |
34 | 44 | return worker_config |
35 | 45 |
|
36 | 46 | def test_old_configs_master(self) -> None: |
@@ -77,7 +87,13 @@ def test_old_configs_appservice_worker(self) -> None: |
77 | 87 | Tests old (legacy) config options. This is for the worker's config. |
78 | 88 | """ |
79 | 89 | appservice_worker_config = self._make_worker_config( |
80 | | - worker_app="synapse.app.appservice", worker_name="worker1" |
| 90 | + worker_app="synapse.app.appservice", |
| 91 | + worker_name="worker1", |
| 92 | + extras={ |
| 93 | + # Set notify_appservices to false for the initialiser's config, |
| 94 | + # so that it doesn't raise an exception here. |
| 95 | + "notify_appservices": False, |
| 96 | + }, |
81 | 97 | ) |
82 | 98 |
|
83 | 99 | with self.assertRaises(ConfigError): |
@@ -179,7 +195,13 @@ def test_transitional_configs_appservice_worker(self) -> None: |
179 | 195 | Tests transitional (legacy + new) config options. This is for the worker's config. |
180 | 196 | """ |
181 | 197 | appservice_worker_config = self._make_worker_config( |
182 | | - worker_app="synapse.app.appservice", worker_name="worker1" |
| 198 | + worker_app="synapse.app.appservice", |
| 199 | + worker_name="worker1", |
| 200 | + extras={ |
| 201 | + # Set notify_appservices to false for the initialiser's config, |
| 202 | + # so that it doesn't raise an exception here. |
| 203 | + "notify_appservices": False, |
| 204 | + }, |
183 | 205 | ) |
184 | 206 |
|
185 | 207 | self.assertTrue( |
|
0 commit comments