Skip to content

Commit ca2eebd

Browse files
committed
test: improve cursor_streaming_large_test assertions and reduce duplication
- Tighten batch count assertion to exactly 11 (10 full batches + 1 final empty batch) - Replace 4 nearly identical fetch_all_* functions with single generic helper - Keep semantic aliases for backwards compatibility - All tests pass
1 parent ab729d1 commit ca2eebd

1 file changed

Lines changed: 18 additions & 30 deletions

File tree

test/cursor_streaming_large_test.exs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ defmodule EctoLibSql.CursorStreamingLargeTest do
231231
# Fetch multiple batches
232232
batch_count = count_batches(state, cursor, query, max_rows: 100)
233233

234-
# Should have multiple batches of 100 rows plus remainder
235-
assert batch_count >= 9, "Should have at least 9 batches for 1000 rows with batch size 100"
234+
# Should have exactly 11 batches: 10 with 100 rows each, plus 1 final batch with 0 rows
235+
assert batch_count == 11, "Should have exactly 11 batches for 1000 rows with batch size 100"
236236
end
237237

238238
test "cursor with aggregation query", %{state: state} do
@@ -369,24 +369,32 @@ defmodule EctoLibSql.CursorStreamingLargeTest do
369369
end
370370
end
371371

372-
defp fetch_all_binary_rows(state, cursor, query, opts) do
372+
# Generic helper to collect all rows from a cursor by repeatedly fetching batches
373+
defp fetch_all_cursor_rows(state, cursor, query, opts) do
373374
case EctoLibSql.handle_fetch(query, cursor, opts, state) do
374375
{:cont, result, next_state} ->
375-
result.rows ++ fetch_all_binary_rows(next_state, cursor, query, opts)
376+
result.rows ++ fetch_all_cursor_rows(next_state, cursor, query, opts)
376377

377378
{:halt, result, _state} ->
378379
result.rows
379380
end
380381
end
381382

383+
# Aliases for backwards compatibility and semantic clarity
384+
defp fetch_all_binary_rows(state, cursor, query, opts) do
385+
fetch_all_cursor_rows(state, cursor, query, opts)
386+
end
387+
382388
defp fetch_all_computed_rows(state, cursor, query, opts) do
383-
case EctoLibSql.handle_fetch(query, cursor, opts, state) do
384-
{:cont, result, next_state} ->
385-
result.rows ++ fetch_all_computed_rows(next_state, cursor, query, opts)
389+
fetch_all_cursor_rows(state, cursor, query, opts)
390+
end
386391

387-
{:halt, result, _state} ->
388-
result.rows
389-
end
392+
defp fetch_all_group_rows(state, cursor, query, opts) do
393+
fetch_all_cursor_rows(state, cursor, query, opts)
394+
end
395+
396+
defp fetch_all_distinct_rows(state, cursor, query, opts) do
397+
fetch_all_cursor_rows(state, cursor, query, opts)
390398
end
391399

392400
defp count_batches(state, cursor, query, opts) do
@@ -398,24 +406,4 @@ defmodule EctoLibSql.CursorStreamingLargeTest do
398406
1
399407
end
400408
end
401-
402-
defp fetch_all_group_rows(state, cursor, query, opts) do
403-
case EctoLibSql.handle_fetch(query, cursor, opts, state) do
404-
{:cont, result, next_state} ->
405-
result.rows ++ fetch_all_group_rows(next_state, cursor, query, opts)
406-
407-
{:halt, result, _state} ->
408-
result.rows
409-
end
410-
end
411-
412-
defp fetch_all_distinct_rows(state, cursor, query, opts) do
413-
case EctoLibSql.handle_fetch(query, cursor, opts, state) do
414-
{:cont, result, next_state} ->
415-
result.rows ++ fetch_all_distinct_rows(next_state, cursor, query, opts)
416-
417-
{:halt, result, _state} ->
418-
result.rows
419-
end
420-
end
421409
end

0 commit comments

Comments
 (0)