Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Convert one of the setup_test_homeservers to `make_test_homeserver_…
Browse files Browse the repository at this point in the history
…synchronous`

and pass in the homeserver rather than calling a same-named function to ask for one.

Later commits will jiggle things around to make this sensible.
  • Loading branch information
reivilibre committed Dec 3, 2021
1 parent 5640992 commit f7ec6e7
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions tests/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
from synapse.types import JsonDict
from synapse.util import Clock

from tests.utils import setup_test_homeserver as _sth

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -450,14 +449,11 @@ def _(res):
return d


def setup_test_homeserver(cleanup_func, *args, **kwargs):
def make_test_homeserver_synchronous(server: HomeServer) -> None:
"""
Set up a synchronous test server, driven by the reactor used by
the homeserver.
Make the given test homeserver's database interactions synchronous.
"""
server = _sth(cleanup_func, *args, **kwargs)

# Make the thread pool synchronous.
clock = server.get_clock()

for database in server.get_datastores().databases:
Expand Down Expand Up @@ -485,15 +481,14 @@ def runInteraction(interaction, *args, **kwargs):

pool.runWithConnection = runWithConnection
pool.runInteraction = runInteraction
# Replace the thread pool with a threadless 'thread' pool
pool.threadpool = ThreadPool(clock._reactor)
pool.running = True

# We've just changed the Databases to run DB transactions on the same
# thread, so we need to disable the dedicated thread behaviour.
server.get_datastores().main.USE_DEDICATED_DB_THREADS_FOR_EVENT_FETCHING = False

return server


def get_clock() -> Tuple[ThreadedMemoryReactorClock, Clock]:
clock = ThreadedMemoryReactorClock()
Expand Down

0 comments on commit f7ec6e7

Please sign in to comment.