Skip to content

Commit 532699e

Browse files
committed
fix: improve pool load test robustness and error handling
- Replace unsafe max Float64 value (1.7976931348623157e308) with platform-safe 1.0e307 to prevent flaky tests from platform-specific rounding - Replace unsafe Enum.reduce with defensive Enum.reduce_while in concurrent transaction test to gracefully handle insert failures instead of crashing - Add explicit error handling in reduce_while with clear error payloads for debugging - Improves test reliability and diagnostic value
1 parent e7683a3 commit 532699e

1 file changed

Lines changed: 27 additions & 12 deletions

File tree

test/pool_load_test.exs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,10 +1096,10 @@ defmodule EctoLibSql.PoolLoadTest do
10961096
[],
10971097
state
10981098
),
1099-
# Large integer
1099+
# Large integer (using 1.0e307 instead of near-max Float64 to avoid platform-specific rounding)
11001100
EctoLibSql.handle_execute(
11011101
"INSERT INTO typed_data (int_val, float_val, text_val, timestamp_val) VALUES (?, ?, ?, ?)",
1102-
[9_223_372_036_854_775_807, 1.7976931348623157e308, "max_#{task_num}", now],
1102+
[9_223_372_036_854_775_807, 1.0e307, "max_#{task_num}", now],
11031103
[],
11041104
state
11051105
)
@@ -1377,19 +1377,34 @@ defmodule EctoLibSql.PoolLoadTest do
13771377
# Insert edge-case values in transaction, threading state through
13781378
edge_values = generate_edge_case_values(task_num)
13791379

1380-
final_trx_state =
1381-
Enum.reduce(edge_values, trx_state, fn value, acc_state ->
1382-
{:ok, _query, _result, new_state} = insert_edge_case_value(acc_state, value)
1383-
new_state
1384-
end)
1380+
# Use reduce_while to defensively handle insert failures
1381+
with {:ok, final_trx_state} <-
1382+
Enum.reduce_while(edge_values, {:ok, trx_state}, fn value, acc ->
1383+
case acc do
1384+
{:ok, acc_state} ->
1385+
case insert_edge_case_value(acc_state, value) do
1386+
{:ok, _query, _result, new_state} ->
1387+
{:cont, {:ok, new_state}}
13851388

1386-
# Always rollback - edge-case data should not persist
1387-
case EctoLibSql.Native.rollback(final_trx_state) do
1388-
{:ok, _state} ->
1389-
{:ok, :edge_cases_rolled_back}
1389+
{:error, reason, _state} ->
1390+
{:halt, {:error, {:insert_failed, value, reason}}}
1391+
end
1392+
1393+
error ->
1394+
{:halt, error}
1395+
end
1396+
end) do
1397+
# Always rollback - edge-case data should not persist
1398+
case EctoLibSql.Native.rollback(final_trx_state) do
1399+
{:ok, _state} ->
1400+
{:ok, :edge_cases_rolled_back}
13901401

1402+
{:error, reason} ->
1403+
{:error, {:rollback_failed, reason}}
1404+
end
1405+
else
13911406
{:error, reason} ->
1392-
{:error, {:rollback_failed, reason}}
1407+
{:error, {:edge_case_insertion_failed, reason}}
13931408
end
13941409
after
13951410
EctoLibSql.disconnect([], state)

0 commit comments

Comments
 (0)