diff options
author | Sean Quah <8349537+squahtx@users.noreply.github.com> | 2022-04-27 14:58:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-27 14:58:26 +0100 |
commit | 78b99de7c206b106340e12cdee0af9aa246bd5ad (patch) | |
tree | 7eb94bb066b8ed0b23fa160056b5e9bcdb29dd8e /tests/rest/client/test_presence.py | |
parent | Add a module API to allow modules to edit push rule actions (#12406) (diff) | |
download | synapse-78b99de7c206b106340e12cdee0af9aa246bd5ad.tar.xz |
Prefer `make_awaitable` over `defer.succeed` in tests (#12505)
When configuring the return values of mocks, prefer awaitables from `make_awaitable` over `defer.succeed`. `Deferred`s are only awaitable once, so it is inappropriate for a mock to return the same `Deferred` multiple times. Also update `run_in_background` to support functions that return arbitrary awaitables. Signed-off-by: Sean Quah <seanq@element.io>
Diffstat (limited to 'tests/rest/client/test_presence.py')
-rw-r--r-- | tests/rest/client/test_presence.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/tests/rest/client/test_presence.py b/tests/rest/client/test_presence.py index 0abe378fe4..b3738a0304 100644 --- a/tests/rest/client/test_presence.py +++ b/tests/rest/client/test_presence.py @@ -14,7 +14,6 @@ from http import HTTPStatus from unittest.mock import Mock -from twisted.internet import defer from twisted.test.proto_helpers import MemoryReactor from synapse.handlers.presence import PresenceHandler @@ -24,6 +23,7 @@ from synapse.types import UserID from synapse.util import Clock from tests import unittest +from tests.test_utils import make_awaitable class PresenceTestCase(unittest.HomeserverTestCase): @@ -37,7 +37,7 @@ class PresenceTestCase(unittest.HomeserverTestCase): def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer: presence_handler = Mock(spec=PresenceHandler) - presence_handler.set_state.return_value = defer.succeed(None) + presence_handler.set_state.return_value = make_awaitable(None) hs = self.setup_test_homeserver( "red", |