test_transactions.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright 2018 New Vector 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 synapse.storage.databases.main.transactions import DestinationRetryTimings
  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.assertEqual(
  33. DestinationRetryTimings(
  34. retry_last_ts=50, retry_interval=100, failure_ts=1000
  35. ),
  36. r,
  37. )
  38. def test_initial_set_transactions(self):
  39. """Tests that we can successfully set the destination retries (there
  40. was a bug around invalidating the cache that broke this)
  41. """
  42. d = self.store.set_destination_retry_timings("example.com", 1000, 50, 100)
  43. self.get_success(d)
  44. def test_large_destination_retry(self):
  45. d = self.store.set_destination_retry_timings(
  46. "example.com", MAX_RETRY_INTERVAL, MAX_RETRY_INTERVAL, MAX_RETRY_INTERVAL
  47. )
  48. self.get_success(d)
  49. d = self.store.get_destination_retry_timings("example.com")
  50. self.get_success(d)