Files
turso/antithesis-tests/stress-composer/parallel_driver_schema_rollback.py
Pekka Enberg b895381ae6 Revert "Merge 'Reachable assertions in Antithesis Python Test for better logging' from Pedro Muniz"
This reverts commit dbbc3f5190, reversing
changes made to 1cd5a49705. We're missing
some mandatory parameters, causing these to fail under Antithesis.
2025-07-08 17:51:12 +03:00

57 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env -S python3 -u
import json
import turso
from antithesis.assertions import always
from antithesis.random import get_random
# Get initial state
try:
con_init = turso.connect("init_state.db")
except Exception as e:
print(f"Error connecting to database: {e}")
exit(0)
cur_init = con_init.cursor()
tbl_len = cur_init.execute("SELECT count FROM tables").fetchone()[0]
selected_tbl = get_random() % tbl_len
tbl_schema = json.loads(cur_init.execute(
f"SELECT schema FROM schemas WHERE tbl = {selected_tbl}").fetchone()[0])
tbl_name = f"tbl_{selected_tbl}"
try:
con = turso.connect("stress_composer.db")
except Exception as e:
print(f"Failed to open stress_composer.db. Exiting... {e}")
exit(0)
cur = con.cursor()
cur.execute(
"SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = '" + tbl_name + "'")
result = cur.fetchone()
if result is None:
print(f"Table {tbl_name} not found")
exit(0)
else:
schema_before = result[0]
cur.execute("BEGIN TRANSACTION")
cur.execute("ALTER TABLE " + tbl_name + " RENAME TO " + tbl_name + "_old")
con.rollback()
cur = con.cursor()
cur.execute(
"SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = '" + tbl_name + "'")
schema_after = cur.fetchone()[0]
always(schema_before == schema_after,
"schema should be the same after rollback", {})