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

Commit ec10bdd

Browse files
authored
Speed up unit tests when using PostgreSQL (#8450)
1 parent 6289467 commit ec10bdd

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

changelog.d/8450.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Speed up unit tests when using PostgreSQL.

synapse/storage/databases/main/events_worker.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ class EventRedactBehaviour(Names):
7474

7575

7676
class EventsWorkerStore(SQLBaseStore):
77+
# Whether to use dedicated DB threads for event fetching. This is only used
78+
# if there are multiple DB threads available. When used will lock the DB
79+
# thread for periods of time (so unit tests want to disable this when they
80+
# run DB transactions on the main thread). See EVENT_QUEUE_* for more
81+
# options controlling this.
82+
USE_DEDICATED_DB_THREADS_FOR_EVENT_FETCHING = True
83+
7784
def __init__(self, database: DatabasePool, db_conn, hs):
7885
super().__init__(database, db_conn, hs)
7986

@@ -522,7 +529,11 @@ def _do_fetch(self, conn):
522529

523530
if not event_list:
524531
single_threaded = self.database_engine.single_threaded
525-
if single_threaded or i > EVENT_QUEUE_ITERATIONS:
532+
if (
533+
not self.USE_DEDICATED_DB_THREADS_FOR_EVENT_FETCHING
534+
or single_threaded
535+
or i > EVENT_QUEUE_ITERATIONS
536+
):
526537
self._event_fetch_ongoing -= 1
527538
return
528539
else:

tests/server.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ def runInteraction(interaction, *args, **kwargs):
372372
pool.threadpool = ThreadPool(clock._reactor)
373373
pool.running = True
374374

375+
# We've just changed the Databases to run DB transactions on the same
376+
# thread, so we need to disable the dedicated thread behaviour.
377+
server.get_datastores().main.USE_DEDICATED_DB_THREADS_FOR_EVENT_FETCHING = False
378+
375379
return server
376380

377381

0 commit comments

Comments
 (0)