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:
Pekka Enberg
2025-10-21 19:18:43 +03:00
parent d2d995a9c0
commit 4805c6b06b
9 changed files with 67 additions and 23 deletions

View File

@@ -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()

View File

@@ -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()

View File

@@ -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

View File

@@ -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()

View File

@@ -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()

View File

@@ -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

View File

@@ -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

View File

@@ -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", {})

View File

@@ -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