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

Commit 7d70582

Browse files
authored
Fix broken export-data admin command and add a test for it to CI (#11078)
Fix broken export-data admin command and add a test for it to CI
1 parent 37b845d commit 7d70582

File tree

4 files changed

+93
-8
lines changed

4 files changed

+93
-8
lines changed
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
3+
# Test for the export-data admin command against sqlite and postgres
4+
5+
set -xe
6+
cd `dirname $0`/../..
7+
8+
echo "--- Install dependencies"
9+
10+
# Install dependencies for this test.
11+
pip install psycopg2
12+
13+
# Install Synapse itself. This won't update any libraries.
14+
pip install -e .
15+
16+
echo "--- Generate the signing key"
17+
18+
# Generate the server's signing key.
19+
python -m synapse.app.homeserver --generate-keys -c .ci/sqlite-config.yaml
20+
21+
echo "--- Prepare test database"
22+
23+
# Make sure the SQLite3 database is using the latest schema and has no pending background update.
24+
scripts/update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
25+
26+
# Run the export-data command on the sqlite test database
27+
python -m synapse.app.admin_cmd -c .ci/sqlite-config.yaml export-data @anon-20191002_181700-832:localhost:8800 \
28+
--output-directory /tmp/export_data
29+
30+
# Test that the output directory exists and contains the rooms directory
31+
dir="/tmp/export_data/rooms"
32+
if [ -d "$dir" ]; then
33+
echo "Command successful, this test passes"
34+
else
35+
echo "No output directories found, the command fails against a sqlite database."
36+
exit 1
37+
fi
38+
39+
# Create the PostgreSQL database.
40+
.ci/scripts/postgres_exec.py "CREATE DATABASE synapse"
41+
42+
# Port the SQLite databse to postgres so we can check command works against postgres
43+
echo "+++ Port SQLite3 databse to postgres"
44+
scripts/synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
45+
46+
# Run the export-data command on postgres database
47+
python -m synapse.app.admin_cmd -c .ci/postgres-config.yaml export-data @anon-20191002_181700-832:localhost:8800 \
48+
--output-directory /tmp/export_data2
49+
50+
# Test that the output directory exists and contains the rooms directory
51+
dir2="/tmp/export_data2/rooms"
52+
if [ -d "$dir2" ]; then
53+
echo "Command successful, this test passes"
54+
else
55+
echo "No output directories found, the command fails against a postgres database."
56+
exit 1
57+
fi

.github/workflows/tests.yml

+29
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,35 @@ jobs:
253253
/logs/results.tap
254254
/logs/**/*.log*
255255
256+
export-data:
257+
if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
258+
needs: [linting-done, portdb]
259+
runs-on: ubuntu-latest
260+
env:
261+
TOP: ${{ github.workspace }}
262+
263+
services:
264+
postgres:
265+
image: postgres
266+
ports:
267+
- 5432:5432
268+
env:
269+
POSTGRES_PASSWORD: "postgres"
270+
POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
271+
options: >-
272+
--health-cmd pg_isready
273+
--health-interval 10s
274+
--health-timeout 5s
275+
--health-retries 5
276+
277+
steps:
278+
- uses: actions/checkout@v2
279+
- run: sudo apt-get -qq install xmlsec1
280+
- uses: actions/setup-python@v2
281+
with:
282+
python-version: "3.9"
283+
- run: .ci/scripts/test_export_data_command.sh
284+
256285
portdb:
257286
if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
258287
needs: linting-done

changelog.d/11078.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix broken export-data admin command and add test script checking the command to CI.

synapse/app/admin_cmd.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from synapse.replication.slave.storage.receipts import SlavedReceiptsStore
4040
from synapse.replication.slave.storage.registration import SlavedRegistrationStore
4141
from synapse.server import HomeServer
42+
from synapse.storage.databases.main.room import RoomWorkerStore
4243
from synapse.util.logcontext import LoggingContext
4344
from synapse.util.versionstring import get_version_string
4445

@@ -58,6 +59,7 @@ class AdminCmdSlavedStore(
5859
SlavedEventStore,
5960
SlavedClientIpStore,
6061
BaseSlavedStore,
62+
RoomWorkerStore,
6163
):
6264
pass
6365

@@ -185,11 +187,7 @@ def start(config_options):
185187
# a full worker config.
186188
config.worker.worker_app = "synapse.app.admin_cmd"
187189

188-
if (
189-
not config.worker.worker_daemonize
190-
and not config.worker.worker_log_file
191-
and not config.worker.worker_log_config
192-
):
190+
if not config.worker.worker_daemonize and not config.worker.worker_log_config:
193191
# Since we're meant to be run as a "command" let's not redirect stdio
194192
# unless we've actually set log config.
195193
config.logging.no_redirect_stdio = True
@@ -198,9 +196,9 @@ def start(config_options):
198196
config.server.update_user_directory = False
199197
config.worker.run_background_tasks = False
200198
config.worker.start_pushers = False
201-
config.pusher_shard_config.instances = []
199+
config.worker.pusher_shard_config.instances = []
202200
config.worker.send_federation = False
203-
config.federation_shard_config.instances = []
201+
config.worker.federation_shard_config.instances = []
204202

205203
synapse.events.USE_FROZEN_DICTS = config.server.use_frozen_dicts
206204

@@ -221,7 +219,7 @@ def start(config_options):
221219

222220
async def run():
223221
with LoggingContext("command"):
224-
_base.start(ss)
222+
await _base.start(ss)
225223
await args.func(ss, args)
226224

227225
_base.start_worker_reactor(

0 commit comments

Comments
 (0)