From 196299050692b51ce95f59611358575842d35425 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 29 May 2025 16:08:46 +0300 Subject: [PATCH] antithesis-tests: Don't fail tests on unique constraint violation Unique constraint violation is not an error. --- .../stress-composer/parallel_driver_insert.py | 16 ++++++++++++---- .../stress-composer/parallel_driver_update.py | 14 +++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/antithesis-tests/stress-composer/parallel_driver_insert.py b/antithesis-tests/stress-composer/parallel_driver_insert.py index 89d4daea0..2be4fa45e 100755 --- a/antithesis-tests/stress-composer/parallel_driver_insert.py +++ b/antithesis-tests/stress-composer/parallel_driver_insert.py @@ -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 diff --git a/antithesis-tests/stress-composer/parallel_driver_update.py b/antithesis-tests/stress-composer/parallel_driver_update.py index fc707cb8b..703329883 100755 --- a/antithesis-tests/stress-composer/parallel_driver_update.py +++ b/antithesis-tests/stress-composer/parallel_driver_update.py @@ -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