test_transactions.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  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 synapse.util.retryutils import MAX_RETRY_INTERVAL
  16. from tests.unittest import HomeserverTestCase
  17. class TransactionStoreTestCase(HomeserverTestCase):
  18. def prepare(self, reactor, clock, homeserver):
  19. self.store = homeserver.get_datastore()
  20. def test_get_set_transactions(self):
  21. """Tests that we can successfully get a non-existent entry for
  22. destination retries, as well as testing tht we can set and get
  23. correctly.
  24. """
  25. d = self.store.get_destination_retry_timings("example.com")
  26. r = self.get_success(d)
  27. self.assertIsNone(r)
  28. d = self.store.set_destination_retry_timings("example.com", 1000, 50, 100)
  29. self.get_success(d)
  30. d = self.store.get_destination_retry_timings("example.com")
  31. r = self.get_success(d)
  32. self.assert_dict(
  33. {"retry_last_ts": 50, "retry_interval": 100, "failure_ts": 1000}, r
  34. )
  35. def test_initial_set_transactions(self):
  36. """Tests that we can successfully set the destination retries (there
  37. was a bug around invalidating the cache that broke this)
  38. """
  39. d = self.store.set_destination_retry_timings("example.com", 1000, 50, 100)
  40. self.get_success(d)
  41. def test_large_destination_retry(self):
  42. d = self.store.set_destination_retry_timings(
  43. "example.com", MAX_RETRY_INTERVAL, MAX_RETRY_INTERVAL, MAX_RETRY_INTERVAL
  44. )
  45. self.get_success(d)
  46. d = self.store.get_destination_retry_timings("example.com")
  47. self.get_success(d)