mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 00:24:21 +01:00
antithesis-tests: Don't fail tests on ProgrammingError
The ProgrammingError exception is thrown when tables, indexes, or columns are dropped in parallel. Let's not fail the Antithesis test drivers when that happens.
This commit is contained in:
@@ -126,6 +126,10 @@ try:
|
||||
con.commit()
|
||||
con_init.commit()
|
||||
|
||||
except turso.ProgrammingError as e:
|
||||
print(f"Table/column might have been dropped in parallel: {e}")
|
||||
con.rollback()
|
||||
con_init.rollback()
|
||||
except turso.OperationalError as e:
|
||||
print(f"Failed to alter table: {e}")
|
||||
con.rollback()
|
||||
|
||||
@@ -90,6 +90,9 @@ if create_composite:
|
||||
""")
|
||||
con_init.commit()
|
||||
print(f"Successfully created composite index: {index_name}")
|
||||
except turso.ProgrammingError as e:
|
||||
print(f"Table/column might have been dropped in parallel: {e}")
|
||||
con.rollback()
|
||||
except turso.OperationalError as e:
|
||||
print(f"Failed to create composite index: {e}")
|
||||
con.rollback()
|
||||
@@ -137,6 +140,9 @@ else:
|
||||
""")
|
||||
con_init.commit()
|
||||
print(f"Successfully created {idx_type} index: {index_name}")
|
||||
except turso.ProgrammingError as e:
|
||||
print(f"Table/column might have been dropped in parallel: {e}")
|
||||
con.rollback()
|
||||
except turso.OperationalError as e:
|
||||
print(f"Failed to create index: {e}")
|
||||
con.rollback()
|
||||
|
||||
@@ -48,6 +48,10 @@ for i in range(deletions):
|
||||
cur.execute(f"""
|
||||
DELETE FROM tbl_{selected_tbl} WHERE {where_clause}
|
||||
""")
|
||||
except turso.ProgrammingError:
|
||||
# Table/column might have been dropped in parallel - this is expected
|
||||
con.rollback()
|
||||
break
|
||||
except turso.OperationalError:
|
||||
con.rollback()
|
||||
# Re-raise other operational errors
|
||||
|
||||
@@ -55,11 +55,13 @@ try:
|
||||
con_init.commit()
|
||||
|
||||
print(f"Successfully dropped index: {index_name}")
|
||||
except turso.ProgrammingError as e:
|
||||
print(f"Index {index_name} already dropped in parallel: {e}")
|
||||
con.rollback()
|
||||
except turso.OperationalError as e:
|
||||
print(f"Failed to drop index: {e}")
|
||||
con.rollback()
|
||||
except Exception as e:
|
||||
# Handle case where index might not exist in indexes table
|
||||
print(f"Warning: Could not remove index from metadata: {e}")
|
||||
|
||||
con.commit()
|
||||
|
||||
@@ -31,9 +31,14 @@ except Exception as e:
|
||||
|
||||
cur = con.cursor()
|
||||
|
||||
cur.execute(f"DROP TABLE tbl_{selected_tbl}")
|
||||
|
||||
con.commit()
|
||||
try:
|
||||
cur.execute(f"DROP TABLE tbl_{selected_tbl}")
|
||||
con.commit()
|
||||
print(f"Successfully dropped table tbl_{selected_tbl}")
|
||||
except turso.ProgrammingError as e:
|
||||
# Table might have been dropped in parallel - this is expected
|
||||
print(f"Table tbl_{selected_tbl} already dropped in parallel: {e}")
|
||||
con.rollback()
|
||||
|
||||
con.close()
|
||||
|
||||
|
||||
@@ -46,6 +46,10 @@ for i in range(insertions):
|
||||
INSERT INTO tbl_{selected_tbl} ({cols})
|
||||
VALUES ({", ".join(values)})
|
||||
""")
|
||||
except turso.ProgrammingError:
|
||||
# Table/column might have been dropped in parallel - this is expected
|
||||
con.rollback()
|
||||
break
|
||||
except turso.OperationalError as e:
|
||||
if "UNIQUE constraint failed" in str(e):
|
||||
# Ignore UNIQUE constraint violations
|
||||
|
||||
@@ -46,6 +46,10 @@ for i in range(insertions):
|
||||
INSERT INTO tbl_{selected_tbl} ({cols})
|
||||
VALUES ({", ".join(values)})
|
||||
""")
|
||||
except turso.ProgrammingError:
|
||||
# Table/column might have been dropped in parallel - this is expected
|
||||
con.rollback()
|
||||
break
|
||||
except turso.OperationalError as e:
|
||||
if "UNIQUE constraint failed" in str(e):
|
||||
# Ignore UNIQUE constraint violations
|
||||
|
||||
@@ -35,25 +35,36 @@ except Exception as e:
|
||||
exit(0)
|
||||
|
||||
cur = con.cursor()
|
||||
cur.execute("SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = '" + tbl_name + "'")
|
||||
|
||||
result = cur.fetchone()
|
||||
try:
|
||||
cur.execute("SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = '" + tbl_name + "'")
|
||||
|
||||
if result is None:
|
||||
print(f"Table {tbl_name} not found")
|
||||
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 + "'")
|
||||
|
||||
result_after = cur.fetchone()
|
||||
if result_after is None:
|
||||
print(f"Table {tbl_name} dropped in parallel after rollback")
|
||||
exit(0)
|
||||
|
||||
schema_after = result_after[0]
|
||||
|
||||
always(schema_before == schema_after, "schema should be the same after rollback", {})
|
||||
except turso.ProgrammingError as e:
|
||||
print(f"Table {tbl_name} dropped in parallel: {e}")
|
||||
con.rollback()
|
||||
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", {})
|
||||
|
||||
@@ -60,6 +60,10 @@ for i in range(updates):
|
||||
cur.execute(f"""
|
||||
UPDATE tbl_{selected_tbl} SET {set_clause} WHERE {where_clause}
|
||||
""")
|
||||
except turso.ProgrammingError:
|
||||
# Table/column might have been dropped in parallel - this is expected
|
||||
con.rollback()
|
||||
break
|
||||
except turso.OperationalError as e:
|
||||
if "UNIQUE constraint failed" in str(e):
|
||||
# Ignore UNIQUE constraint violations
|
||||
|
||||
Reference in New Issue
Block a user