@@ -766,9 +766,7 @@ def test_get_backfill_points_in_room(self):
766766 self .store .get_backfill_points_in_room (room_id , depth_map ["B" ], limit = 100 )
767767 )
768768 backfill_event_ids = [backfill_point [0 ] for backfill_point in backfill_points ]
769- self .assertListEqual (
770- backfill_event_ids , ["b6" , "b5" , "b4" , "2" , "b3" , "b2" , "b1" ]
771- )
769+ self .assertEqual (backfill_event_ids , ["b6" , "b5" , "b4" , "2" , "b3" , "b2" , "b1" ])
772770
773771 # Try at "A"
774772 backfill_points = self .get_success (
@@ -814,7 +812,7 @@ def test_get_backfill_points_in_room_excludes_events_we_have_attempted(
814812 )
815813 backfill_event_ids = [backfill_point [0 ] for backfill_point in backfill_points ]
816814 # Only the backfill points that we didn't record earlier exist here.
817- self .assertListEqual (backfill_event_ids , ["b6" , "2" , "b1" ])
815+ self .assertEqual (backfill_event_ids , ["b6" , "2" , "b1" ])
818816
819817 def test_get_backfill_points_in_room_attempted_event_retry_after_backoff_duration (
820818 self ,
@@ -860,7 +858,7 @@ def test_get_backfill_points_in_room_attempted_event_retry_after_backoff_duratio
860858 self .store .get_backfill_points_in_room (room_id , depth_map ["A" ], limit = 100 )
861859 )
862860 backfill_event_ids = [backfill_point [0 ] for backfill_point in backfill_points ]
863- self .assertListEqual (backfill_event_ids , ["b3" , "b2" ])
861+ self .assertEqual (backfill_event_ids , ["b3" , "b2" ])
864862
865863 # Now advance time by 20 hours (above 2^4 because we made 4 attemps) and
866864 # see if we can now backfill it
@@ -871,7 +869,48 @@ def test_get_backfill_points_in_room_attempted_event_retry_after_backoff_duratio
871869 self .store .get_backfill_points_in_room (room_id , depth_map ["A" ], limit = 100 )
872870 )
873871 backfill_event_ids = [backfill_point [0 ] for backfill_point in backfill_points ]
874- self .assertListEqual (backfill_event_ids , ["b3" , "b2" , "b1" ])
872+ self .assertEqual (backfill_event_ids , ["b3" , "b2" , "b1" ])
873+
874+ def test_get_backfill_points_in_room_works_after_many_failed_pull_attempts_that_could_naively_overflow (
875+ self ,
876+ ) -> None :
877+ """
878+ A test that reproduces #13929 (Postgres only).
879+
880+ Test to make sure we can still get backfill points after many failed pull
881+ attempts that cause us to backoff to the limit. Even if the backoff formula
882+ would tell us to wait for more seconds than can be expressed in a 32 bit
883+ signed int.
884+ """
885+ setup_info = self ._setup_room_for_backfill_tests ()
886+ room_id = setup_info .room_id
887+ depth_map = setup_info .depth_map
888+
889+ # Pretend that we have tried and failed 10 times to backfill event b1.
890+ for _ in range (10 ):
891+ self .get_success (
892+ self .store .record_event_failed_pull_attempt (room_id , "b1" , "fake cause" )
893+ )
894+
895+ # If the backoff periods grow without limit:
896+ # After the first failed attempt, we would have backed off for 1 << 1 = 2 hours.
897+ # After the second failed attempt we would have backed off for 1 << 2 = 4 hours,
898+ # so after the 10th failed attempt we should backoff for 1 << 10 == 1024 hours.
899+ # Wait 1100 hours just so we have a nice round number.
900+ self .reactor .advance (datetime .timedelta (hours = 1100 ).total_seconds ())
901+
902+ # 1024 hours in milliseconds is 1024 * 3600000, which exceeds the largest 32 bit
903+ # signed integer. The bug we're reproducing is that this overflow causes an
904+ # error in postgres preventing us from fetching a set of backwards extremities
905+ # to retry fetching.
906+ backfill_points = self .get_success (
907+ self .store .get_backfill_points_in_room (room_id , depth_map ["A" ], limit = 100 )
908+ )
909+
910+ # We should aim to fetch all backoff points: b1's latest backoff period has
911+ # expired, and we haven't tried the rest.
912+ backfill_event_ids = [backfill_point [0 ] for backfill_point in backfill_points ]
913+ self .assertEqual (backfill_event_ids , ["b3" , "b2" , "b1" ])
875914
876915 def _setup_room_for_insertion_backfill_tests (self ) -> _BackfillSetupInfo :
877916 """
@@ -965,9 +1004,7 @@ def test_get_insertion_event_backward_extremities_in_room(self):
9651004 )
9661005 )
9671006 backfill_event_ids = [backfill_point [0 ] for backfill_point in backfill_points ]
968- self .assertListEqual (
969- backfill_event_ids , ["insertion_eventB" , "insertion_eventA" ]
970- )
1007+ self .assertEqual (backfill_event_ids , ["insertion_eventB" , "insertion_eventA" ])
9711008
9721009 # Try at "insertion_eventA"
9731010 backfill_points = self .get_success (
@@ -1011,7 +1048,7 @@ def test_get_insertion_event_backward_extremities_in_room_excludes_events_we_hav
10111048 )
10121049 backfill_event_ids = [backfill_point [0 ] for backfill_point in backfill_points ]
10131050 # Only the backfill points that we didn't record earlier exist here.
1014- self .assertListEqual (backfill_event_ids , ["insertion_eventB" ])
1051+ self .assertEqual (backfill_event_ids , ["insertion_eventB" ])
10151052
10161053 def test_get_insertion_event_backward_extremities_in_room_attempted_event_retry_after_backoff_duration (
10171054 self ,
@@ -1069,7 +1106,7 @@ def test_get_insertion_event_backward_extremities_in_room_attempted_event_retry_
10691106 )
10701107 )
10711108 backfill_event_ids = [backfill_point [0 ] for backfill_point in backfill_points ]
1072- self .assertListEqual (backfill_event_ids , [])
1109+ self .assertEqual (backfill_event_ids , [])
10731110
10741111 # Now advance time by 20 hours (above 2^4 because we made 4 attemps) and
10751112 # see if we can now backfill it
@@ -1083,7 +1120,7 @@ def test_get_insertion_event_backward_extremities_in_room_attempted_event_retry_
10831120 )
10841121 )
10851122 backfill_event_ids = [backfill_point [0 ] for backfill_point in backfill_points ]
1086- self .assertListEqual (backfill_event_ids , ["insertion_eventA" ])
1123+ self .assertEqual (backfill_event_ids , ["insertion_eventA" ])
10871124
10881125
10891126@attr .s
0 commit comments