Spaces:
Running
Running
Update tests/test_migration.py
Browse files- tests/test_migration.py +16 -2
tests/test_migration.py
CHANGED
|
@@ -184,8 +184,17 @@ con.execute(
|
|
| 184 |
"VALUES (?, ?, strftime('%s','now'), 'pending', 'member')",
|
| 185 |
(gid, 2)
|
| 186 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
con.commit()
|
| 188 |
convs_before_second = con.execute("SELECT COUNT(*) FROM conversations").fetchone()[0]
|
|
|
|
| 189 |
con.close()
|
| 190 |
|
| 191 |
# ------------------------------------------------------------------
|
|
@@ -200,13 +209,18 @@ rc2 = con.execute("SELECT read_at FROM read_receipts WHERE user_id=1 AND message
|
|
| 200 |
pend = con.execute(
|
| 201 |
"SELECT status FROM conversation_members WHERE conversation_id=? AND user_id=2", (gid,)
|
| 202 |
).fetchone()
|
|
|
|
|
|
|
|
|
|
| 203 |
con.close()
|
| 204 |
-
if n2 !=
|
| 205 |
-
failures.append(f"second run duplicated/lost data: msgs {
|
| 206 |
if rc2 != 1700000002000:
|
| 207 |
failures.append(f"read_at re-multiplied on second run: {rc2}")
|
| 208 |
if not pend or pend[0] != "pending":
|
| 209 |
failures.append(f"pending invite was not preserved across restart: {pend}")
|
|
|
|
|
|
|
| 210 |
|
| 211 |
print("\n==== RESULT ====")
|
| 212 |
if failures:
|
|
|
|
| 184 |
"VALUES (?, ?, strftime('%s','now'), 'pending', 'member')",
|
| 185 |
(gid, 2)
|
| 186 |
)
|
| 187 |
+
# Regression: on restart the startup backfill used to rewrite every DM/group
|
| 188 |
+
# message back into Global (id 1) because its NOT IN list only contained id 1.
|
| 189 |
+
# Put a real message in this non-global conversation and ensure it survives.
|
| 190 |
+
con.execute(
|
| 191 |
+
"INSERT INTO messages (sender_id, encrypted_content, timestamp_ms, conversation_id) "
|
| 192 |
+
"VALUES (1, 'CIPHERTEXT_DM', 1700000003000, ?)",
|
| 193 |
+
(gid,)
|
| 194 |
+
)
|
| 195 |
con.commit()
|
| 196 |
convs_before_second = con.execute("SELECT COUNT(*) FROM conversations").fetchone()[0]
|
| 197 |
+
msgs_before_second = con.execute("SELECT COUNT(*) FROM messages").fetchone()[0]
|
| 198 |
con.close()
|
| 199 |
|
| 200 |
# ------------------------------------------------------------------
|
|
|
|
| 209 |
pend = con.execute(
|
| 210 |
"SELECT status FROM conversation_members WHERE conversation_id=? AND user_id=2", (gid,)
|
| 211 |
).fetchone()
|
| 212 |
+
dm_msg = con.execute(
|
| 213 |
+
"SELECT conversation_id FROM messages WHERE encrypted_content='CIPHERTEXT_DM'"
|
| 214 |
+
).fetchone()
|
| 215 |
con.close()
|
| 216 |
+
if n2 != msgs_before_second or c2 != convs_before_second or u2 != n_users:
|
| 217 |
+
failures.append(f"second run duplicated/lost data: msgs {msgs_before_second}->{n2}, convs {convs_before_second}->{c2}, users {n_users}->{u2}")
|
| 218 |
if rc2 != 1700000002000:
|
| 219 |
failures.append(f"read_at re-multiplied on second run: {rc2}")
|
| 220 |
if not pend or pend[0] != "pending":
|
| 221 |
failures.append(f"pending invite was not preserved across restart: {pend}")
|
| 222 |
+
if not dm_msg or dm_msg[0] != gid:
|
| 223 |
+
failures.append(f"private-chat message was moved to Global on restart: {dm_msg}")
|
| 224 |
|
| 225 |
print("\n==== RESULT ====")
|
| 226 |
if failures:
|