diff options
author | Erik Johnston <erik@matrix.org> | 2019-12-18 10:45:12 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-18 10:45:12 +0000 |
commit | 2284eb3a533a2df04784df08da28e67d6588a5ea (patch) | |
tree | df75df4b3eba90e8299c8bae61157d075a0d423b /tests/server.py | |
parent | Merge branch 'master' into develop (diff) | |
download | synapse-2284eb3a533a2df04784df08da28e67d6588a5ea.tar.xz |
Add database config class (#6513)
This encapsulates config for a given database and is the way to get new connections.
Diffstat (limited to 'tests/server.py')
-rw-r--r-- | tests/server.py | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/tests/server.py b/tests/server.py index 2b7cf4242e..a554dfdd57 100644 --- a/tests/server.py +++ b/tests/server.py @@ -302,41 +302,42 @@ def setup_test_homeserver(cleanup_func, *args, **kwargs): Set up a synchronous test server, driven by the reactor used by the homeserver. """ - d = _sth(cleanup_func, *args, **kwargs).result + server = _sth(cleanup_func, *args, **kwargs) - if isinstance(d, Failure): - d.raiseException() + database = server.config.database.get_single_database() # Make the thread pool synchronous. - clock = d.get_clock() - pool = d.get_db_pool() - - def runWithConnection(func, *args, **kwargs): - return threads.deferToThreadPool( - pool._reactor, - pool.threadpool, - pool._runWithConnection, - func, - *args, - **kwargs - ) - - def runInteraction(interaction, *args, **kwargs): - return threads.deferToThreadPool( - pool._reactor, - pool.threadpool, - pool._runInteraction, - interaction, - *args, - **kwargs - ) + clock = server.get_clock() + + for database in server.get_datastores().databases: + pool = database._db_pool + + def runWithConnection(func, *args, **kwargs): + return threads.deferToThreadPool( + pool._reactor, + pool.threadpool, + pool._runWithConnection, + func, + *args, + **kwargs + ) + + def runInteraction(interaction, *args, **kwargs): + return threads.deferToThreadPool( + pool._reactor, + pool.threadpool, + pool._runInteraction, + interaction, + *args, + **kwargs + ) - if pool: pool.runWithConnection = runWithConnection pool.runInteraction = runInteraction pool.threadpool = ThreadPool(clock._reactor) pool.running = True - return d + + return server def get_clock(): |