|
| 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 | +from twisted.internet.defer import ensureDeferred |
| 15 | + |
| 16 | +from synapse.rest.client import room |
| 17 | + |
| 18 | +from tests.replication._base import BaseMultiWorkerStreamTestCase |
| 19 | + |
| 20 | + |
| 21 | +class PartialStateStreamsTestCase(BaseMultiWorkerStreamTestCase): |
| 22 | + servlets = [room.register_servlets] |
| 23 | + hijack_auth = True |
| 24 | + user_id = "@bob:test" |
| 25 | + |
| 26 | + def setUp(self): |
| 27 | + super().setUp() |
| 28 | + self.store = self.hs.get_datastores().main |
| 29 | + |
| 30 | + def test_un_partial_stated_room_unblocks_over_replication(self) -> None: |
| 31 | + """ |
| 32 | + Tests that, when a room is un-partial-stated on another worker, |
| 33 | + pending calls to `await_full_state` get unblocked. |
| 34 | + """ |
| 35 | + |
| 36 | + # Make a room. |
| 37 | + room_id = self.helper.create_room_as("@bob:test") |
| 38 | + # Mark the room as partial-stated. |
| 39 | + self.get_success( |
| 40 | + self.store.store_partial_state_room(room_id, ["serv1", "serv2"], 0, "serv1") |
| 41 | + ) |
| 42 | + |
| 43 | + worker = self.make_worker_hs("synapse.app.generic_worker") |
| 44 | + |
| 45 | + # On the worker, attempt to get the current hosts in the room |
| 46 | + d = ensureDeferred( |
| 47 | + worker.get_storage_controllers().state.get_current_hosts_in_room(room_id) |
| 48 | + ) |
| 49 | + |
| 50 | + self.reactor.advance(0.1) |
| 51 | + |
| 52 | + # This should block |
| 53 | + self.assertFalse( |
| 54 | + d.called, "get_current_hosts_in_room/await_full_state did not block" |
| 55 | + ) |
| 56 | + |
| 57 | + # On the master, clear the partial state flag. |
| 58 | + self.get_success(self.store.clear_partial_state_room(room_id)) |
| 59 | + |
| 60 | + self.reactor.advance(0.1) |
| 61 | + |
| 62 | + # The worker should have unblocked |
| 63 | + self.assertTrue( |
| 64 | + d.called, "get_current_hosts_in_room/await_full_state did not unblock" |
| 65 | + ) |
0 commit comments