test_transactions.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. r = self.get_success(self.store.get_destination_retry_timings("example.com"))
  31. self.assertIsNone(r)
  32. self.get_success(
  33. self.store.set_destination_retry_timings("example.com", 1000, 50, 100)
  34. )
  35. r = self.get_success(self.store.get_destination_retry_timings("example.com"))
  36. self.assertEqual(
  37. DestinationRetryTimings(
  38. retry_last_ts=50, retry_interval=100, failure_ts=1000
  39. ),
  40. r,
  41. )
  42. def test_initial_set_transactions(self) -> None:
  43. """Tests that we can successfully set the destination retries (there
  44. was a bug around invalidating the cache that broke this)
  45. """
  46. d = self.store.set_destination_retry_timings("example.com", 1000, 50, 100)
  47. self.get_success(d)
  48. def test_large_destination_retry(self) -> None:
  49. d = self.store.set_destination_retry_timings(
  50. "example.com", MAX_RETRY_INTERVAL, MAX_RETRY_INTERVAL, MAX_RETRY_INTERVAL
  51. )
  52. self.get_success(d)
  53. d2 = self.store.get_destination_retry_timings("example.com")
  54. self.get_success(d2)