mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 22:14:55 -04:00
Add database config class (#6513)
This encapsulates config for a given database and is the way to get new connections.
This commit is contained in:
parent
91ccfe9f37
commit
2284eb3a53
19 changed files with 286 additions and 208 deletions
|
@ -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()
|
||||
clock = server.get_clock()
|
||||
|
||||
def runWithConnection(func, *args, **kwargs):
|
||||
return threads.deferToThreadPool(
|
||||
pool._reactor,
|
||||
pool.threadpool,
|
||||
pool._runWithConnection,
|
||||
func,
|
||||
*args,
|
||||
**kwargs
|
||||
)
|
||||
for database in server.get_datastores().databases:
|
||||
pool = database._db_pool
|
||||
|
||||
def runInteraction(interaction, *args, **kwargs):
|
||||
return threads.deferToThreadPool(
|
||||
pool._reactor,
|
||||
pool.threadpool,
|
||||
pool._runInteraction,
|
||||
interaction,
|
||||
*args,
|
||||
**kwargs
|
||||
)
|
||||
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():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue