Skip to content

Commit a54933b

Browse files
committed
fix: Address CodeRabbit PR review comments
- Fix struct update pattern in security_test.exs (use map update after pattern match assertion) - Replace unreachable :deallocated clause with :halt in cursor test - Fix unused variable warnings (_state and _i) - Improve test cleanup to properly stop repo before file removal - Add -journal file cleanup to prevent stale files
1 parent 623d2b5 commit a54933b

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

test/ecto_migration_test.exs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,21 @@ defmodule Ecto.Adapters.LibSql.MigrationTest do
1414
setup do
1515
# Start a fresh repo for each test with a unique database file.
1616
test_db = "z_ecto_libsql_test-migrations_#{:erlang.unique_integer([:positive])}.db"
17-
{:ok, _} = start_supervised({TestRepo, database: test_db})
17+
{:ok, pid} = start_supervised({TestRepo, database: test_db})
1818

1919
on_exit(fn ->
20+
# Stop the repo before cleaning up files.
21+
if Process.alive?(pid) do
22+
stop_supervised(TestRepo)
23+
end
24+
25+
# Small delay to ensure file handles are released.
26+
Process.sleep(10)
27+
2028
File.rm(test_db)
2129
File.rm(test_db <> "-shm")
2230
File.rm(test_db <> "-wal")
31+
File.rm(test_db <> "-journal")
2332
end)
2433

2534
# Foreign keys are disabled by default in SQLite - tests that need them will enable them explicitly.

test/fuzz_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ defmodule EctoLibSql.FuzzTest do
3838
File.rm(db_path)
3939
File.rm(db_path <> "-shm")
4040
File.rm(db_path <> "-wal")
41+
File.rm(db_path <> "-journal")
4142
end)
4243

4344
{:ok, state: state, db_path: db_path}

test/security_test.exs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ defmodule EctoLibSql.SecurityTest do
3838

3939
# Try to use connection A's transaction on connection B by forcing trx_id
4040
# This tests that transactions are properly scoped to their connection
41-
state_b_fake = %EctoLibSql.State{state_b | trx_id: trx_id_a}
41+
%EctoLibSql.State{} = state_b
42+
state_b_fake = %{state_b | trx_id: trx_id_a}
4243

4344
case EctoLibSql.handle_execute(
4445
"SELECT 1",
@@ -234,7 +235,7 @@ defmodule EctoLibSql.SecurityTest do
234235
{:cont, _result, _state} ->
235236
flunk("Connection B should not access Connection A's cursor")
236237

237-
{:deallocated, _result, _state} ->
238+
{:halt, _result, _state} ->
238239
flunk("Connection B should not access Connection A's cursor")
239240
end
240241

@@ -309,7 +310,7 @@ defmodule EctoLibSql.SecurityTest do
309310
)
310311

311312
for i <- 1..100 do
312-
{:ok, _, _, state} =
313+
{:ok, _, _, _state} =
313314
EctoLibSql.handle_execute(
314315
"INSERT INTO concurrent_test (value) VALUES (?)",
315316
["value_#{i}"],
@@ -337,7 +338,7 @@ defmodule EctoLibSql.SecurityTest do
337338

338339
# Try to fetch concurrently from multiple processes
339340
tasks =
340-
for i <- 1..5 do
341+
for _i <- 1..5 do
341342
Task.async(fn ->
342343
EctoLibSql.handle_fetch(
343344
%EctoLibSql.Query{statement: "SELECT * FROM concurrent_test"},

0 commit comments

Comments
 (0)