Skip to content

Commit 825d1e2

Browse files
committed
fix: ensure isolated test data by clearing tables before assertions
- Add DELETE FROM test_data before concurrent load tests to ensure exact row count assertions - Affects three tests: 'connection recovers after query error', 'concurrent load with only NULL values', 'concurrent load with only empty strings' - Prevents test failures when previous tests leave residual data in shared database - Ensures each test has a predictable, clean starting state for row count verification
1 parent 532699e commit 825d1e2

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

test/pool_load_test.exs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,12 @@ defmodule EctoLibSql.PoolLoadTest do
403403
# Note: This test is sequential (not concurrent) and runs by default.
404404
# It complements connection_recovery_test.exs by using file-based database.
405405
test "connection recovers after query error", %{test_db: test_db} do
406+
# Clear table first to ensure exact row count assertions
406407
{:ok, state} = EctoLibSql.connect(database: test_db, busy_timeout: 30_000)
407408

409+
{:ok, _, _, state} =
410+
EctoLibSql.handle_execute("DELETE FROM test_data", [], [], state)
411+
408412
try do
409413
# Successful insert
410414
{:ok, _query, _result, state} =
@@ -913,6 +917,14 @@ defmodule EctoLibSql.PoolLoadTest do
913917
@tag :slow
914918
@tag :flaky
915919
test "concurrent load with only NULL values", %{test_db: test_db} do
920+
# Clear table first to ensure exact row count assertions
921+
{:ok, state} = EctoLibSql.connect(database: test_db, busy_timeout: 30_000)
922+
923+
{:ok, _, _, state} =
924+
EctoLibSql.handle_execute("DELETE FROM test_data", [], [], state)
925+
926+
EctoLibSql.disconnect([], state)
927+
916928
tasks =
917929
Enum.map(1..10, fn _i ->
918930
Task.async(fn ->
@@ -956,6 +968,14 @@ defmodule EctoLibSql.PoolLoadTest do
956968
@tag :slow
957969
@tag :flaky
958970
test "concurrent load with only empty strings", %{test_db: test_db} do
971+
# Clear table first to ensure exact row count assertions
972+
{:ok, state} = EctoLibSql.connect(database: test_db, busy_timeout: 30_000)
973+
974+
{:ok, _, _, state} =
975+
EctoLibSql.handle_execute("DELETE FROM test_data", [], [], state)
976+
977+
EctoLibSql.disconnect([], state)
978+
959979
tasks =
960980
Enum.map(1..10, fn _i ->
961981
Task.async(fn ->

0 commit comments

Comments
 (0)