_base.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright 2016 OpenMarket Ltd
  2. # Copyright 2018 New Vector Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from unittest.mock import Mock
  16. from tests.replication._base import BaseStreamTestCase
  17. class BaseSlavedStoreTestCase(BaseStreamTestCase):
  18. def make_homeserver(self, reactor, clock):
  19. hs = self.setup_test_homeserver(federation_client=Mock())
  20. return hs
  21. def prepare(self, reactor, clock, hs):
  22. super().prepare(reactor, clock, hs)
  23. self.reconnect()
  24. self.master_store = hs.get_datastore()
  25. self.slaved_store = self.worker_hs.get_datastore()
  26. self.storage = hs.get_storage()
  27. def replicate(self):
  28. """Tell the master side of replication that something has happened, and then
  29. wait for the replication to occur.
  30. """
  31. self.streamer.on_notifier_poke()
  32. self.pump(0.1)
  33. def check(self, method, args, expected_result=None):
  34. master_result = self.get_success(getattr(self.master_store, method)(*args))
  35. slaved_result = self.get_success(getattr(self.slaved_store, method)(*args))
  36. if expected_result is not None:
  37. self.assertEqual(
  38. master_result,
  39. expected_result,
  40. "Expected master result to be %r but was %r"
  41. % (expected_result, master_result),
  42. )
  43. self.assertEqual(
  44. slaved_result,
  45. expected_result,
  46. "Expected slave result to be %r but was %r"
  47. % (expected_result, slaved_result),
  48. )
  49. self.assertEqual(
  50. master_result,
  51. slaved_result,
  52. "Slave result %r does not match master result %r"
  53. % (slaved_result, master_result),
  54. )