antithesis-tests: Don't fail tests on unique constraint violation

Unique constraint violation is not an error.
This commit is contained in:
Pekka Enberg
2025-05-29 16:08:46 +03:00
parent 1653bfb2b3
commit 1962990506
2 changed files with 23 additions and 7 deletions

View File

@@ -24,8 +24,16 @@ print(f'Inserting {insertions} rows...')
for i in range(insertions):
values = [generate_random_value(tbl_schema[f'col_{col}']['data_type']) for col in range(tbl_schema['colCount'])]
cur.execute(f'''
INSERT INTO tbl_{selected_tbl} ({cols})
VALUES ({', '.join(values)})
''')
try:
cur.execute(f'''
INSERT INTO tbl_{selected_tbl} ({cols})
VALUES ({', '.join(values)})
''')
except limbo.OperationalError as e:
if "UNIQUE constraint failed" in str(e):
# Ignore UNIQUE constraint violations
pass
else:
# Re-raise other operational errors
raise

View File

@@ -39,7 +39,15 @@ for i in range(updates):
where_clause = f"col_{pk} = {generate_random_value(tbl_schema[f'col_{pk}']['data_type'])}"
# print(where_clause)
cur.execute(f'''
UPDATE tbl_{selected_tbl} SET {set_clause} WHERE {where_clause}
''')
try:
cur.execute(f'''
UPDATE tbl_{selected_tbl} SET {set_clause} WHERE {where_clause}
''')
except limbo.OperationalError as e:
if "UNIQUE constraint failed" in str(e):
# Ignore UNIQUE constraint violations
pass
else:
# Re-raise other operational errors
raise