test_partial_state.py 2.2 KB

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