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

Stop ignoring tests/server.py #15084

Merged
merged 21 commits into from
Feb 17, 2023
Merged
Changes from 1 commit
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
34 changes: 26 additions & 8 deletions tests/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,30 +602,48 @@ def _make_test_homeserver_synchronous(server: HomeServer) -> None:
for database in server.get_datastores().databases:
pool = database._db_pool

def runWithConnection(func, *args, **kwargs):
return threads.deferToThreadPool(
async def runWithConnection(
func: Callable[..., R],
clokep marked this conversation as resolved.
Show resolved Hide resolved
*args: Any,
db_autocommit: bool = False,
isolation_level: Optional[int] = None,
**kwargs: Any,
) -> R:
clokep marked this conversation as resolved.
Show resolved Hide resolved
return await threads.deferToThreadPool(
pool._reactor,
pool.threadpool,
pool._runWithConnection,
func,
*args,
db_autocommit,
isolation_level,
**kwargs,
)

def runInteraction(interaction, *args, **kwargs):
return threads.deferToThreadPool(
async def runInteraction(
desc: str,
func: Callable[..., R],
*args: Any,
db_autocommit: bool = False,
isolation_level: Optional[int] = None,
**kwargs: Any,
) -> R:
return await threads.deferToThreadPool(
pool._reactor,
pool.threadpool,
pool._runInteraction,
interaction,
desc,
func,
*args,
db_autocommit,
isolation_level,
**kwargs,
)

pool.runWithConnection = runWithConnection
pool.runInteraction = runInteraction
pool.runWithConnection = runWithConnection # type: ignore[assignment]
pool.runInteraction = runInteraction # type: ignore[assignment]
# Replace the thread pool with a threadless 'thread' pool
pool.threadpool = ThreadPool(clock._reactor)
pool.threadpool = ThreadPool(clock._reactor) # type: ignore[assignment]
pool.running = True

# We've just changed the Databases to run DB transactions on the same
Expand Down