Speed up unit tests when using PostgreSQL (#8450)

This commit is contained in:
Erik Johnston 2020-10-02 15:09:31 +01:00 committed by GitHub
parent 62894673e6
commit ec10bdd32b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

1
changelog.d/8450.misc Normal file
View file

@ -0,0 +1 @@
Speed up unit tests when using PostgreSQL.

View file

@ -74,6 +74,13 @@ class EventRedactBehaviour(Names):
class EventsWorkerStore(SQLBaseStore): class EventsWorkerStore(SQLBaseStore):
# Whether to use dedicated DB threads for event fetching. This is only used
# if there are multiple DB threads available. When used will lock the DB
# thread for periods of time (so unit tests want to disable this when they
# run DB transactions on the main thread). See EVENT_QUEUE_* for more
# options controlling this.
USE_DEDICATED_DB_THREADS_FOR_EVENT_FETCHING = True
def __init__(self, database: DatabasePool, db_conn, hs): def __init__(self, database: DatabasePool, db_conn, hs):
super().__init__(database, db_conn, hs) super().__init__(database, db_conn, hs)
@ -522,7 +529,11 @@ class EventsWorkerStore(SQLBaseStore):
if not event_list: if not event_list:
single_threaded = self.database_engine.single_threaded single_threaded = self.database_engine.single_threaded
if single_threaded or i > EVENT_QUEUE_ITERATIONS: if (
not self.USE_DEDICATED_DB_THREADS_FOR_EVENT_FETCHING
or single_threaded
or i > EVENT_QUEUE_ITERATIONS
):
self._event_fetch_ongoing -= 1 self._event_fetch_ongoing -= 1
return return
else: else:

View file

@ -372,6 +372,10 @@ def setup_test_homeserver(cleanup_func, *args, **kwargs):
pool.threadpool = ThreadPool(clock._reactor) pool.threadpool = ThreadPool(clock._reactor)
pool.running = True 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 return server