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

Speed up unit tests when using PostgreSQL #8450

Merged
merged 2 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8450.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Speed up unit tests when using PostgreSQL.
13 changes: 12 additions & 1 deletion synapse/storage/databases/main/events_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ class EventRedactBehaviour(Names):


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):
super().__init__(database, db_conn, hs)

Expand Down Expand Up @@ -522,7 +529,11 @@ def _do_fetch(self, conn):

if not event_list:
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
return
else:
Expand Down
4 changes: 4 additions & 0 deletions tests/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ def runInteraction(interaction, *args, **kwargs):
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


Expand Down