test_transactions.py 2.5 KB

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