From f0bc77465714fbe13862a482b77fbc362a415a25 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Tue, 28 Jul 2026 20:36:00 -0500 Subject: [PATCH] Fix dead-lock if background updates never finish We were advancing time by `0` so the timeout never hit --- tests/unittest.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/unittest.py b/tests/unittest.py index 6b6cf42bd1..af06a49a66 100644 --- a/tests/unittest.py +++ b/tests/unittest.py @@ -78,7 +78,6 @@ from synapse.storage.background_updates import UpdaterStatus from synapse.storage.keys import FetchKeyResult from synapse.types import ISynapseReactor, JsonDict, Requester, UserID, create_requester from synapse.util.clock import CLOCK_SCHEDULE_EPSILON, Clock -from synapse.util.duration import Duration from synapse.util.httpresourcetree import create_resource_tree from tests.server import ( @@ -105,11 +104,6 @@ P = ParamSpec("P") R = TypeVar("R") S = TypeVar("S") -BACKGROUND_UPDATE_TIMEOUT = Duration(seconds=5) -""" -We expect this to be pretty immediate as we're working with an empty database. -""" - class _TypedFailure(Generic[_ExcType], Protocol): """Extension to twisted.Failure, where the 'value' has a certain type.""" @@ -687,7 +681,7 @@ class HomeserverTestCase(TestCase): # We could use `self._wait_for_background_updates(hs)` to accomplish the same # thing but we don't want to start or drive the background updates here. We want # to ensure the homeserver itself is doing that. - start_time_s = reactor.seconds() + loop_count = 0 store = hs.get_datastores().main while not self.get_success( # This check is slightly naive. It only checks if there is anything left in @@ -697,10 +691,9 @@ class HomeserverTestCase(TestCase): # really assert that everything was registered as expected. store.db_pool.updates.has_completed_background_updates() ): - # Timeout if it takes too long. This should be pretty immediate as we're + # 100 loops is arbitrary but we expect this to be pretty immediate as we're # working with an empty database. - current_time_s = reactor.seconds() - if current_time_s - start_time_s > BACKGROUND_UPDATE_TIMEOUT.as_secs(): + if loop_count > 100: background_update_status = store.db_pool.updates.get_status() # Add some better context when we give up @@ -717,7 +710,7 @@ class HomeserverTestCase(TestCase): ) raise AssertionError( - f"Timed out waiting for background updates to complete ({BACKGROUND_UPDATE_TIMEOUT.as_secs()}s). " + "Timed out waiting for background updates to complete. " + extra_message )