From 805be03142f4104403168ec2ac887d79e987d6f2 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Thu, 9 Apr 2026 20:01:45 +0100 Subject: [PATCH] Remove unnecessary calls to `self.pump` --- tests/crypto/test_keyring.py | 1 - tests/federation/test_complexity.py | 10 ------ tests/federation/test_federation_catch_up.py | 1 - tests/http/test_matrixfederationclient.py | 22 ------------ tests/http/test_simple_client.py | 7 ---- tests/media/test_media_storage.py | 2 -- tests/push/test_http.py | 37 -------------------- tests/replication/test_multi_media_repo.py | 29 --------------- tests/rest/client/test_filter.py | 1 - tests/storage/databases/main/test_lock.py | 5 --- tests/storage/databases/main/test_metrics.py | 1 - tests/storage/test_client_ips.py | 2 -- tests/storage/test_roommember.py | 4 --- 13 files changed, 122 deletions(-) diff --git a/tests/crypto/test_keyring.py b/tests/crypto/test_keyring.py index 6bc935f272..3ff408b5ea 100644 --- a/tests/crypto/test_keyring.py +++ b/tests/crypto/test_keyring.py @@ -188,7 +188,6 @@ class KeyringTestCase(unittest.HomeserverTestCase): d2 = ensureDeferred(second_lookup()) - self.pump() # the second request should be pending, but the fetcher should not yet have been # called self.assertEqual(second_lookup_state[0], 1) diff --git a/tests/federation/test_complexity.py b/tests/federation/test_complexity.py index 87b9ffc0c6..c58e20a07e 100644 --- a/tests/federation/test_complexity.py +++ b/tests/federation/test_complexity.py @@ -94,8 +94,6 @@ class RoomComplexityTests(unittest.FederatingHomeserverTestCase): {"membership": "join"}, ) - self.pump() - # The request failed with a SynapseError saying the resource limit was # exceeded. f = self.get_failure(d, SynapseError) @@ -125,8 +123,6 @@ class RoomComplexityTests(unittest.FederatingHomeserverTestCase): {"membership": "join"}, ) - self.pump() - # The request failed with a SynapseError saying the resource limit was # exceeded. f = self.get_failure(d, SynapseError) @@ -170,8 +166,6 @@ class RoomComplexityTests(unittest.FederatingHomeserverTestCase): {"membership": "join"}, ) - self.pump() - # The request failed with a SynapseError saying the resource limit was # exceeded. f = self.get_failure(d, SynapseError) @@ -221,8 +215,6 @@ class RoomComplexityAdminTests(unittest.FederatingHomeserverTestCase): {"membership": "join"}, ) - self.pump() - # The request failed with a SynapseError saying the resource limit was # exceeded. f = self.get_failure(d, SynapseError) @@ -251,7 +243,5 @@ class RoomComplexityAdminTests(unittest.FederatingHomeserverTestCase): {"membership": "join"}, ) - self.pump() - # The request success since the user is an admin self.get_success(d) diff --git a/tests/federation/test_federation_catch_up.py b/tests/federation/test_federation_catch_up.py index fd1ef043bb..dc84d5b0ee 100644 --- a/tests/federation/test_federation_catch_up.py +++ b/tests/federation/test_federation_catch_up.py @@ -153,7 +153,6 @@ class FederationCatchUpTestCases(FederatingHomeserverTestCase): ) self.helper.send(room, "wombats!", tok=u1_token) - self.pump() lsso_1 = self.get_success( self.hs.get_datastores().main.get_destination_last_successful_stream_ordering( diff --git a/tests/http/test_matrixfederationclient.py b/tests/http/test_matrixfederationclient.py index 4792bdc9bc..4d083c30ed 100644 --- a/tests/http/test_matrixfederationclient.py +++ b/tests/http/test_matrixfederationclient.py @@ -133,8 +133,6 @@ class FederationClientTests(HomeserverTestCase): b"%s" % (len(res_json), res_json) ) - self.pump() - res = self.successResultOf(test_d) # check the response is as expected @@ -710,8 +708,6 @@ class FederationClientTests(HomeserverTestCase): b"%s" % (len(return_value), return_value) ) - self.pump() - f = self.failureResultOf(test_d) self.assertIsInstance(f.value, RequestSendFailed) @@ -751,8 +747,6 @@ class FederationClientTests(HomeserverTestCase): b"HTTP/1.1 200 OK\r\nServer: Fake\r\nContent-Type: application/json\r\n\r\n" ) - self.pump() - # should still be waiting self.assertNoResult(test_d) @@ -853,9 +847,6 @@ class FederationClientProxyTests(BaseMultiWorkerStreamTestCase): self.hs.get_federation_http_client().get_json("remoteserv:8008", "foo/bar") ) - # Pump the reactor so our deferred goes through the motions - self.pump() - # Make sure that the request was proxied through the `federation_sender` worker mock_agent_on_federation_sender.request.assert_called_once_with( b"GET", @@ -905,11 +896,6 @@ class FederationClientProxyTests(BaseMultiWorkerStreamTestCase): self.hs.get_federation_http_client().get_json("remoteserv:8008", "foo/bar") ) - # Pump the reactor so our deferred goes through the motions. We pump with 10 - # seconds (0.1 * 100) so the `MatrixFederationHttpClient` runs out of retries - # and finally passes along the error response. - self.pump(0.1) - # Make sure that the request was proxied through the `federation_sender` worker mock_agent_on_federation_sender.request.assert_called_with( b"GET", @@ -984,9 +970,6 @@ class FederationClientProxyTests(BaseMultiWorkerStreamTestCase): ) ) - # Pump the reactor so our deferred goes through the motions - self.pump() - # Make sure that the request was proxied through the `federation_sender` worker mock_agent_on_federation_sender.request.assert_called_once_with( b"GET", @@ -1078,11 +1061,6 @@ class FederationClientProxyTests(BaseMultiWorkerStreamTestCase): self.hs.get_federation_http_client().get_json("remoteserv:8008", "foo/bar") ) - # Pump the reactor so our deferred goes through the motions. We pump with 10 - # seconds (0.1 * 100) so the `MatrixFederationHttpClient` runs out of retries - # and finally passes along the error response. - self.pump(0.1) - # Make sure that the request was *NOT* proxied through the `federation_sender` # worker mock_agent_on_federation_sender.request.assert_not_called() diff --git a/tests/http/test_simple_client.py b/tests/http/test_simple_client.py index 25c0e1081b..774926b5e8 100644 --- a/tests/http/test_simple_client.py +++ b/tests/http/test_simple_client.py @@ -46,7 +46,6 @@ class SimpleHttpClientTests(HomeserverTestCase): If the DNS lookup returns an error, it will bubble up. """ d = defer.ensureDeferred(self.cl.get_json("http://testserv2:8008/foo/bar")) - self.pump() f = self.failureResultOf(d) self.assertIsInstance(f.value, DNSLookupError) @@ -54,8 +53,6 @@ class SimpleHttpClientTests(HomeserverTestCase): def test_client_connection_refused(self) -> None: d = defer.ensureDeferred(self.cl.get_json("http://testserv:8008/foo/bar")) - self.pump() - # Nothing happened yet self.assertNoResult(d) @@ -79,8 +76,6 @@ class SimpleHttpClientTests(HomeserverTestCase): """ d = defer.ensureDeferred(self.cl.get_json("http://testserv:8008/foo/bar")) - self.pump() - # Nothing happened yet self.assertNoResult(d) @@ -106,8 +101,6 @@ class SimpleHttpClientTests(HomeserverTestCase): """ d = defer.ensureDeferred(self.cl.get_json("http://testserv:8008/foo/bar")) - self.pump() - # Nothing happened yet self.assertNoResult(d) diff --git a/tests/media/test_media_storage.py b/tests/media/test_media_storage.py index 631718a366..72818bf41a 100644 --- a/tests/media/test_media_storage.py +++ b/tests/media/test_media_storage.py @@ -845,8 +845,6 @@ class MediaRepoTests(unittest.HomeserverTestCase): HttpResponseException(404, "NOT FOUND", unknown_endpoint) ) - self.pump() - # There should now be another request to the r0 URL. self.assertEqual(len(self.fetches), 2) self.assertEqual(self.fetches[1][1], "example.com") diff --git a/tests/push/test_http.py b/tests/push/test_http.py index ca2ced01ed..f6a7f7755e 100644 --- a/tests/push/test_http.py +++ b/tests/push/test_http.py @@ -159,9 +159,6 @@ class HTTPPusherTests(HomeserverTestCase): self.assertEqual(len(pushers), 1) last_stream_ordering = pushers[0].last_stream_ordering - # Advance time a bit, so the pusher will register something has happened - self.pump() - # It hasn't succeeded yet, so the stream ordering shouldn't have moved pushers = list( self.get_success( @@ -182,7 +179,6 @@ class HTTPPusherTests(HomeserverTestCase): # Make the push succeed self.push_attempts[0][0].callback({}) - self.pump() # The stream ordering has increased pushers = list( @@ -205,7 +201,6 @@ class HTTPPusherTests(HomeserverTestCase): # Make the second push succeed self.push_attempts[1][0].callback({}) - self.pump() # The stream ordering has increased, again pushers = list( @@ -284,12 +279,8 @@ class HTTPPusherTests(HomeserverTestCase): tok=other_access_token, ) - # Advance time a bit, so the pusher will register something has happened - self.pump() - # Make the push succeed self.push_attempts[0][0].callback({}) - self.pump() # Check our push made it with high priority self.assertEqual(len(self.push_attempts), 1) @@ -308,7 +299,6 @@ class HTTPPusherTests(HomeserverTestCase): # Check no push notifications are sent regarding the membership changes # (that would confuse the test) - self.pump() self.assertEqual(len(self.push_attempts), 1) # Send another encrypted event @@ -330,8 +320,6 @@ class HTTPPusherTests(HomeserverTestCase): tok=other_access_token, ) - # Advance time a bit, so the pusher will register something has happened - self.pump() self.assertEqual(len(self.push_attempts), 2) self.assertEqual( self.push_attempts[1][1], "http://example.com/_matrix/push/v1/notify" @@ -385,12 +373,8 @@ class HTTPPusherTests(HomeserverTestCase): # Send a message self.helper.send(room, body="Hi!", tok=other_access_token) - # Advance time a bit, so the pusher will register something has happened - self.pump() - # Make the push succeed self.push_attempts[0][0].callback({}) - self.pump() # Check our push made it with high priority — this is a one-to-one room self.assertEqual(len(self.push_attempts), 1) @@ -406,14 +390,11 @@ class HTTPPusherTests(HomeserverTestCase): # Check no push notifications are sent regarding the membership changes # (that would confuse the test) - self.pump() self.assertEqual(len(self.push_attempts), 1) # Send another event self.helper.send(room, body="Welcome!", tok=other_access_token) - # Advance time a bit, so the pusher will register something has happened - self.pump() self.assertEqual(len(self.push_attempts), 2) self.assertEqual( self.push_attempts[1][1], "http://example.com/_matrix/push/v1/notify" @@ -472,12 +453,8 @@ class HTTPPusherTests(HomeserverTestCase): # Send a message self.helper.send(room, body="Oh, user, hello!", tok=other_access_token) - # Advance time a bit, so the pusher will register something has happened - self.pump() - # Make the push succeed self.push_attempts[0][0].callback({}) - self.pump() # Check our push made it with high priority self.assertEqual(len(self.push_attempts), 1) @@ -489,8 +466,6 @@ class HTTPPusherTests(HomeserverTestCase): # Send another event, this time with no mention self.helper.send(room, body="Are you there?", tok=other_access_token) - # Advance time a bit, so the pusher will register something has happened - self.pump() self.assertEqual(len(self.push_attempts), 2) self.assertEqual( self.push_attempts[1][1], "http://example.com/_matrix/push/v1/notify" @@ -554,12 +529,8 @@ class HTTPPusherTests(HomeserverTestCase): tok=other_access_token, ) - # Advance time a bit, so the pusher will register something has happened - self.pump() - # Make the push succeed self.push_attempts[0][0].callback({}) - self.pump() # Check our push made it with high priority self.assertEqual(len(self.push_attempts), 1) @@ -573,8 +544,6 @@ class HTTPPusherTests(HomeserverTestCase): room, body="@room the spider is gone", tok=yet_another_access_token ) - # Advance time a bit, so the pusher will register something has happened - self.pump() self.assertEqual(len(self.push_attempts), 2) self.assertEqual( self.push_attempts[1][1], "http://example.com/_matrix/push/v1/notify" @@ -703,7 +672,6 @@ class HTTPPusherTests(HomeserverTestCase): self.helper.send(room_id, body="HELLO???", tok=other_access_token) def _advance_time_and_make_push_succeed(self, expected_push_attempts: int) -> None: - self.pump() self.push_attempts[expected_push_attempts - 1][0].callback({}) def _check_push_attempt( @@ -1084,7 +1052,6 @@ class HTTPPusherTests(HomeserverTestCase): index += 1 self.reactor.advance(1) - self.pump() self.assertEqual(len(self.push_attempts), 11) @@ -1150,7 +1117,6 @@ class HTTPPusherTests(HomeserverTestCase): self.helper.send(room, body="Hi!", tok=other_access_token) # Advance time a bit, so the pusher will register something has happened - self.pump() # One push was attempted to be sent self.assertEqual(len(self.push_attempts), 1) @@ -1218,17 +1184,14 @@ class HTTPPusherTests(HomeserverTestCase): self.push_attempts[0][2]["notification"]["content"]["body"], "Message 1" ) self.push_attempts[0][0].callback({}) - self.pump() # Send another message, this time it fails self.helper.send(room, body="Message 2", tok=other_access_token) self.assertEqual(len(self.push_attempts), 2) self.push_attempts[1][0].errback(Exception("couldn't connect")) - self.pump() # Sending yet another message doesn't trigger a push immediately self.helper.send(room, body="Message 3", tok=other_access_token) - self.pump() self.assertEqual(len(self.push_attempts), 2) # .. but waiting for a bit will cause more pushes diff --git a/tests/replication/test_multi_media_repo.py b/tests/replication/test_multi_media_repo.py index 000dbb5594..059a08c3f2 100644 --- a/tests/replication/test_multi_media_repo.py +++ b/tests/replication/test_multi_media_repo.py @@ -97,7 +97,6 @@ class MediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): access_token=self.access_token, await_result=False, ) - self.pump() clients = self.reactor.tcpClients self.assertGreaterEqual(len(clients), 1) @@ -161,8 +160,6 @@ class MediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request.write(b"Hello!") request.finish() - self.pump(0.1) - self.assertEqual(channel.code, 200) self.assertEqual(channel.result["body"], b"Hello!") @@ -187,8 +184,6 @@ class MediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request1.write(b"Hello!") request1.finish() - self.pump(0.1) - self.assertEqual(channel1.code, 200, channel1.result["body"]) self.assertEqual(channel1.result["body"], b"Hello!") @@ -198,8 +193,6 @@ class MediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request2.write(b"Hello!") request2.finish() - self.pump(0.1) - self.assertEqual(channel2.code, 200, channel2.result["body"]) self.assertEqual(channel2.result["body"], b"Hello!") @@ -233,8 +226,6 @@ class MediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request1.write(b"Hello!") request1.finish() - self.pump(0.1) - # With local storage disabled and no storage providers, # we expect a 404 error self.assertEqual(channel1.code, 404, channel1.result["body"]) @@ -245,8 +236,6 @@ class MediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request2.write(b"Hello!") request2.finish() - self.pump(0.1) - # Same for the second request self.assertEqual(channel2.code, 404, channel2.result["body"]) @@ -273,8 +262,6 @@ class MediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request1.write(SMALL_PNG) request1.finish() - self.pump(0.1) - self.assertEqual(channel1.code, 200, channel1.result["body"]) self.assertEqual(channel1.result["body"], SMALL_PNG) @@ -283,8 +270,6 @@ class MediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request2.write(SMALL_PNG) request2.finish() - self.pump(0.1) - self.assertEqual(channel2.code, 200, channel2.result["body"]) self.assertEqual(channel2.result["body"], SMALL_PNG) @@ -359,7 +344,6 @@ class AuthenticatedMediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): access_token=self.access_token, await_result=False, ) - self.pump() clients = self.reactor.tcpClients self.assertGreaterEqual(len(clients), 1) @@ -425,8 +409,6 @@ class AuthenticatedMediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request.write(self.file_data) request.finish() - self.pump(0.1) - self.assertEqual(channel.code, 200) self.assertEqual(channel.result["body"], b"file_to_stream") @@ -453,8 +435,6 @@ class AuthenticatedMediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request1.write(self.file_data) request1.finish() - self.pump(0.1) - self.assertEqual(channel1.code, 200, channel1.result["body"]) self.assertEqual(channel1.result["body"], b"file_to_stream") @@ -467,8 +447,6 @@ class AuthenticatedMediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request2.write(self.file_data) request2.finish() - self.pump(0.1) - self.assertEqual(channel2.code, 200, channel2.result["body"]) self.assertEqual(channel2.result["body"], b"file_to_stream") @@ -501,7 +479,6 @@ class AuthenticatedMediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request1.write(self.file_data) request1.finish() - self.pump(0.1) # With local storage disabled and no storage providers, # we expect a 404 error self.assertEqual(channel1.code, 404, channel1.result["body"]) @@ -515,8 +492,6 @@ class AuthenticatedMediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request2.write(self.file_data) request2.finish() - self.pump(0.1) - self.assertEqual(channel2.code, 404, channel2.result["body"]) # With local storage disabled, no files should be stored locally @@ -547,8 +522,6 @@ class AuthenticatedMediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request1.write(b"\r\n--6067d4698f8d40a0a794ea7d7379d53a--\r\n\r\n") request1.finish() - self.pump(0.1) - self.assertEqual(channel1.code, 200, channel1.result["body"]) self.assertEqual(channel1.result["body"], SMALL_PNG) @@ -562,8 +535,6 @@ class AuthenticatedMediaRepoShardTestCase(BaseMultiWorkerStreamTestCase): request2.write(b"\r\n--6067d4698f8d40a0a794ea7d7379d53a--\r\n\r\n") request2.finish() - self.pump(0.1) - self.assertEqual(channel2.code, 200, channel2.result["body"]) self.assertEqual(channel2.result["body"], SMALL_PNG) diff --git a/tests/rest/client/test_filter.py b/tests/rest/client/test_filter.py index 0897c67ac3..3e9d999cd7 100644 --- a/tests/rest/client/test_filter.py +++ b/tests/rest/client/test_filter.py @@ -57,7 +57,6 @@ class FilterTestCase(unittest.HomeserverTestCase): user_id=UserID.from_string(FilterTestCase.user_id), filter_id=0 ) ) - self.pump() self.assertEqual(filter, self.EXAMPLE_FILTER) def test_add_filter_for_other_user(self) -> None: diff --git a/tests/storage/databases/main/test_lock.py b/tests/storage/databases/main/test_lock.py index 622eb96ded..493c1194de 100644 --- a/tests/storage/databases/main/test_lock.py +++ b/tests/storage/databases/main/test_lock.py @@ -66,16 +66,11 @@ class LockTestCase(unittest.HomeserverTestCase): task2 = defer.ensureDeferred(task()) task3 = defer.ensureDeferred(task()) - # Give the reactor a kick so that the database transaction returns. - self.pump() - release_lock.callback(None) # Run the tasks to completion. self.get_success(task1) - self.pump() self.get_success(task2) - self.pump() self.get_success(task3) # At most one task should have held the lock at a time. diff --git a/tests/storage/databases/main/test_metrics.py b/tests/storage/databases/main/test_metrics.py index be59e1b67e..c0acdb83f9 100644 --- a/tests/storage/databases/main/test_metrics.py +++ b/tests/storage/databases/main/test_metrics.py @@ -55,7 +55,6 @@ class ExtremStatisticsTestCase(HomeserverTestCase): # Let it run for a while, then pull out the statistics from the # Prometheus client registry self.reactor.advance(60 * 60 * 1000) - self.pump(1) items = list( filter( diff --git a/tests/storage/test_client_ips.py b/tests/storage/test_client_ips.py index bd68f2aaa1..1a484e19f4 100644 --- a/tests/storage/test_client_ips.py +++ b/tests/storage/test_client_ips.py @@ -101,7 +101,6 @@ class ClientIpStoreTestCase(unittest.HomeserverTestCase): ) ) self.reactor.advance(200) - self.pump(0) result = cast( list[tuple[str, str, str, str | None, int]], @@ -132,7 +131,6 @@ class ClientIpStoreTestCase(unittest.HomeserverTestCase): ) ) self.reactor.advance(10) - self.pump(0) result = cast( list[tuple[str, str, str, str | None, int]], diff --git a/tests/storage/test_roommember.py b/tests/storage/test_roommember.py index f8d64e8ce6..abc08f69b7 100644 --- a/tests/storage/test_roommember.py +++ b/tests/storage/test_roommember.py @@ -100,8 +100,6 @@ class RoomMemberStoreTestCase(unittest.HomeserverTestCase): self.inject_room_member(self.room, self.u_bob, Membership.JOIN) self.inject_room_member(self.room, self.u_charlie.to_string(), Membership.JOIN) - self.pump() - self.assertTrue("_known_servers_count" not in self.store.__dict__.keys()) @unittest.override_config( @@ -114,8 +112,6 @@ class RoomMemberStoreTestCase(unittest.HomeserverTestCase): # Initialises to 1 -- itself self.assertEqual(self.store._known_servers_count, 1) - self.pump() - # No rooms have been joined, so technically the SQL returns 0, but it # will still say it knows about itself. self.assertEqual(self.store._known_servers_count, 1)