_base.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright 2016 OpenMarket Ltd
  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 import defer
  15. from tests import unittest
  16. from mock import Mock, NonCallableMock
  17. from tests.utils import setup_test_homeserver
  18. from synapse.replication.resource import ReplicationResource
  19. class BaseSlavedStoreTestCase(unittest.TestCase):
  20. @defer.inlineCallbacks
  21. def setUp(self):
  22. self.hs = yield setup_test_homeserver(
  23. "blue",
  24. http_client=None,
  25. replication_layer=Mock(),
  26. ratelimiter=NonCallableMock(spec_set=[
  27. "send_message",
  28. ]),
  29. )
  30. self.hs.get_ratelimiter().send_message.return_value = (True, 0)
  31. self.replication = ReplicationResource(self.hs)
  32. self.master_store = self.hs.get_datastore()
  33. self.slaved_store = self.STORE_TYPE(self.hs.get_db_conn(), self.hs)
  34. self.event_id = 0
  35. @defer.inlineCallbacks
  36. def replicate(self):
  37. streams = self.slaved_store.stream_positions()
  38. result = yield self.replication.replicate(streams, 100)
  39. yield self.slaved_store.process_replication(result)
  40. @defer.inlineCallbacks
  41. def check(self, method, args, expected_result=None):
  42. master_result = yield getattr(self.master_store, method)(*args)
  43. slaved_result = yield getattr(self.slaved_store, method)(*args)
  44. if expected_result is not None:
  45. self.assertEqual(master_result, expected_result)
  46. self.assertEqual(slaved_result, expected_result)
  47. self.assertEqual(master_result, slaved_result)