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

Commit 58214db

Browse files
authored
Allow enabling the asyncio reactor in complement (#14858)
Signed-off-by: Jason Little [email protected]
1 parent 1d3a54a commit 58214db

File tree

6 files changed

+42
-4
lines changed

6 files changed

+42
-4
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,11 @@ jobs:
541541

542542
- run: |
543543
set -o pipefail
544-
POSTGRES=${{ (matrix.database == 'Postgres') && 1 || '' }} WORKERS=${{ (matrix.arrangement == 'workers') && 1 || '' }} COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -json 2>&1 | synapse/.ci/scripts/gotestfmt
544+
COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -json 2>&1 | synapse/.ci/scripts/gotestfmt
545545
shell: bash
546+
env:
547+
POSTGRES: ${{ (matrix.database == 'Postgres') && 1 || '' }}
548+
WORKERS: ${{ (matrix.arrangement == 'workers') && 1 || '' }}
546549
name: Run Complement Tests
547550
548551
cargo-test:

changelog.d/14858.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Run the integration test suites with the asyncio reactor enabled in CI.

docker/complement/conf/start_for_complement.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -e
66

77
echo "Complement Synapse launcher"
88
echo " Args: $@"
9-
echo " Env: SYNAPSE_COMPLEMENT_DATABASE=$SYNAPSE_COMPLEMENT_DATABASE SYNAPSE_COMPLEMENT_USE_WORKERS=$SYNAPSE_COMPLEMENT_USE_WORKERS"
9+
echo " Env: SYNAPSE_COMPLEMENT_DATABASE=$SYNAPSE_COMPLEMENT_DATABASE SYNAPSE_COMPLEMENT_USE_WORKERS=$SYNAPSE_COMPLEMENT_USE_WORKERS SYNAPSE_COMPLEMENT_USE_ASYNCIO_REACTOR=$SYNAPSE_COMPLEMENT_USE_ASYNCIO_REACTOR"
1010

1111
function log {
1212
d=$(date +"%Y-%m-%d %H:%M:%S,%3N")
@@ -76,6 +76,17 @@ else
7676
fi
7777

7878

79+
if [[ -n "$SYNAPSE_COMPLEMENT_USE_ASYNCIO_REACTOR" ]]; then
80+
if [[ -n "$SYNAPSE_USE_EXPERIMENTAL_FORKING_LAUNCHER" ]]; then
81+
export SYNAPSE_COMPLEMENT_FORKING_LAUNCHER_ASYNC_IO_REACTOR="1"
82+
else
83+
export SYNAPSE_ASYNC_IO_REACTOR="1"
84+
fi
85+
else
86+
export SYNAPSE_ASYNC_IO_REACTOR="0"
87+
fi
88+
89+
7990
# Add Complement's appservice registration directory, if there is one
8091
# (It can be absent when there are no application services in this test!)
8192
if [ -d /complement/appservice ]; then

docs/development/contributing_guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ The above will run a monolithic (single-process) Synapse with SQLite as the data
332332
[here](https://github.com/matrix-org/synapse/blob/develop/docker/configure_workers_and_start.py#L54).
333333
A safe example would be `WORKER_TYPES="federation_inbound, federation_sender, synchrotron"`.
334334
See the [worker documentation](../workers.md) for additional information on workers.
335+
- Passing `ASYNCIO_REACTOR=1` as an environment variable to use the Twisted asyncio reactor instead of the default one.
335336
336337
To increase the log level for the tests, set `SYNAPSE_TEST_LOG_LEVEL`, e.g:
337338
```sh

scripts-dev/complement.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ else
228228
test_tags="$test_tags,msc2716"
229229
fi
230230

231+
if [[ -n "$ASYNCIO_REACTOR" ]]; then
232+
# Enable the Twisted asyncio reactor
233+
export PASS_SYNAPSE_COMPLEMENT_USE_ASYNCIO_REACTOR=true
234+
fi
235+
231236

232237
if [[ -n "$SYNAPSE_TEST_LOG_LEVEL" ]]; then
233238
# Set the log level to what is desired

synapse/app/complement_fork_starter.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,33 @@ def _worker_entrypoint(
110110
and then kick off the worker's main() function.
111111
"""
112112

113+
from synapse.util.stringutils import strtobool
114+
113115
sys.argv = args
114116

115117
# reset the custom signal handlers that we installed, so that the children start
116118
# from a clean slate.
117119
for sig, handler in _original_signal_handlers.items():
118120
signal.signal(sig, handler)
119121

120-
from twisted.internet.epollreactor import EPollReactor
122+
# Install the asyncio reactor if the
123+
# SYNAPSE_COMPLEMENT_FORKING_LAUNCHER_ASYNC_IO_REACTOR is set to 1. The
124+
# SYNAPSE_ASYNC_IO_REACTOR variable would be used, but then causes
125+
# synapse/__init__.py to also try to install an asyncio reactor.
126+
if strtobool(
127+
os.environ.get("SYNAPSE_COMPLEMENT_FORKING_LAUNCHER_ASYNC_IO_REACTOR", "0")
128+
):
129+
import asyncio
130+
131+
from twisted.internet.asyncioreactor import AsyncioSelectorReactor
132+
133+
reactor = AsyncioSelectorReactor(asyncio.get_event_loop())
134+
proxy_reactor._install_real_reactor(reactor)
135+
else:
136+
from twisted.internet.epollreactor import EPollReactor
137+
138+
proxy_reactor._install_real_reactor(EPollReactor())
121139

122-
proxy_reactor._install_real_reactor(EPollReactor())
123140
func()
124141

125142

0 commit comments

Comments
 (0)