fix(tests): use real matrix data for upgrade state
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@ -1,22 +1,65 @@
|
||||
"""matrix-synapse — UPGRADE overlay (Phase 1e HC3): data-continuity, assertion-only + additive.
|
||||
"""matrix-synapse — UPGRADE overlay (Phase 1e HC3): real application-data continuity.
|
||||
|
||||
ops.pre_upgrade wrote a postgres marker row before the upgrade; the orchestrator performed the
|
||||
upgrade once (generic tier asserted reconverge/serving/moved). This overlay ADDS: the postgres data
|
||||
survived. Read via psql in the `db` service."""
|
||||
ops.pre_upgrade seeds REAL Matrix state before the upgrade: two users, a room, and a message. It
|
||||
persists only the test metadata to `/data/ccci-upgrade-state.json` in the Synapse app volume. The
|
||||
orchestrator then performs the upgrade once (generic tier asserts reconverge/serving/moved). This
|
||||
overlay ADDS: after upgrade, the same Matrix user can still log in and read the pre-upgrade message
|
||||
from the same room.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner"))
|
||||
from harness import lifecycle # noqa: E402
|
||||
from harness import http as harness_http, lifecycle # noqa: E402
|
||||
|
||||
|
||||
def _psql(domain, sql):
|
||||
cmd = f'PGPASSWORD=$(cat /run/secrets/db_password) psql -U synapse -d synapse -tAc "{sql}"'
|
||||
return lifecycle.exec_in_app(domain, ["sh", "-c", cmd], service="db").strip()
|
||||
UPGRADE_STATE = "/data/ccci-upgrade-state.json"
|
||||
|
||||
|
||||
def _login(domain: str, username: str, password: str) -> str:
|
||||
s, body = harness_http.http_post(
|
||||
f"https://{domain}/_matrix/client/v3/login",
|
||||
data={
|
||||
"type": "m.login.password",
|
||||
"identifier": {"type": "m.id.user", "user": username},
|
||||
"password": password,
|
||||
},
|
||||
)
|
||||
assert s == 200, f"login {username} HTTP {s}: {body!r}"
|
||||
token = (body or {}).get("access_token")
|
||||
assert isinstance(token, str) and token, f"login returned no access_token: {body!r}"
|
||||
return token
|
||||
|
||||
|
||||
def _auth(token: str) -> dict:
|
||||
return {"Authorization": f"Bearer {token}"}
|
||||
|
||||
|
||||
def _upgrade_state(domain: str) -> dict:
|
||||
raw = lifecycle.exec_in_app(domain, ["cat", UPGRADE_STATE]).strip()
|
||||
state = json.loads(raw)
|
||||
assert isinstance(state, dict), f"upgrade state is not a dict: {state!r}"
|
||||
return state
|
||||
|
||||
|
||||
def test_upgrade_preserves_data(live_app):
|
||||
assert (
|
||||
_psql(live_app, "SELECT v FROM ci_marker;") == "upgrade-survives"
|
||||
), "postgres data did not survive the upgrade"
|
||||
state = _upgrade_state(live_app)
|
||||
user_b = state["user_b"]
|
||||
password = state["password"]
|
||||
room_id = state["room_id"]
|
||||
marker = state["marker"]
|
||||
|
||||
token = _login(live_app, user_b, password)
|
||||
s, body = harness_http.http_get(
|
||||
f"https://{live_app}/_matrix/client/v3/rooms/{room_id}/messages?dir=b&limit=20",
|
||||
headers=_auth(token),
|
||||
)
|
||||
assert s == 200, f"read messages HTTP {s}: {body!r}"
|
||||
chunk = (body or {}).get("chunk", [])
|
||||
bodies = [e.get("content", {}).get("body", "") for e in chunk if isinstance(e, dict)]
|
||||
assert marker in bodies, (
|
||||
f"post-upgrade user {user_b!r} did not see pre-upgrade marker {marker!r}; "
|
||||
f"room={room_id!r} messages={bodies[:10]}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user