test_transactions.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 twisted.test.proto_helpers import MemoryReactor
  15. from synapse.server import HomeServer
  16. from synapse.storage.databases.main.transactions import DestinationRetryTimings
  17. from synapse.util import Clock
  18. from synapse.util.retryutils import MAX_RETRY_INTERVAL
  19. from tests.unittest import HomeserverTestCase
  20. class TransactionStoreTestCase(HomeserverTestCase):
  21. def prepare(
  22. self, reactor: MemoryReactor, clock: Clock, homeserver: HomeServer
  23. ) -> None:
  24. self.store = homeserver.get_datastores().main
  25. def test_get_set_transactions(self) -> None:
  26. """Tests that we can successfully get a non-existent entry for
  27. destination retries, as well as testing tht we can set and get
  28. correctly.
  29. """
  30. d = self.store.get_destination_retry_timings("example.com")
  31. r = self.get_success(d)
  32. self.assertIsNone(r)
  33. d = self.store.set_destination_retry_timings("example.com", 1000, 50, 100)
  34. self.get_success(d)
  35. d = self.store.get_destination_retry_timings("example.com")
  36. r = self.get_success(d)
  37. self.assertEqual(
  38. DestinationRetryTimings(
  39. retry_last_ts=50, retry_interval=100, failure_ts=1000
  40. ),
  41. r,
  42. )
  43. def test_initial_set_transactions(self) -> None:
  44. """Tests that we can successfully set the destination retries (there
  45. was a bug around invalidating the cache that broke this)
  46. """
  47. d = self.store.set_destination_retry_timings("example.com", 1000, 50, 100)
  48. self.get_success(d)
  49. def test_large_destination_retry(self) -> None:
  50. d = self.store.set_destination_retry_timings(
  51. "example.com", MAX_RETRY_INTERVAL, MAX_RETRY_INTERVAL, MAX_RETRY_INTERVAL
  52. )
  53. self.get_success(d)
  54. d2 = self.store.get_destination_retry_timings("example.com")
  55. self.get_success(d2)