the more tests I write, the more deadlocks I run into

The LLM wants to add max_cases to ExUnit.start(max_cases: 2) and shrink the config/test.ex App.Repo pool_size. I feel like these are bandaids and there's something fundamentally wrong with my test suite. Any tips/tricks for things to look for? Some anti-patterns in my generators.ex functions?
Bread Crumbs:
> Error returned from: App.Accounts.User.register_with_password

Unknown Error

* ** (Postgrex.Error) ERROR 40P01 (deadlock_detected) deadlock detected

hint: See server log for query details.

Process 10485 waits for ShareLock on transaction 1240049; blocked by process 10488.
Process 10488 waits for ShareLock on transaction 1240045; blocked by process 10485.
(ecto_sql 3.13.2) lib/ecto/adapters/sql.ex:1098: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto_sql 3.13.2) lib/ecto/adapters/sql.ex:969: Ecto.Adapters.SQL.insert_all/9
Bread Crumbs:
> Error returned from: App.Accounts.User.register_with_password

Unknown Error

* ** (Postgrex.Error) ERROR 40P01 (deadlock_detected) deadlock detected

hint: See server log for query details.

Process 10485 waits for ShareLock on transaction 1240049; blocked by process 10488.
Process 10488 waits for ShareLock on transaction 1240045; blocked by process 10485.
(ecto_sql 3.13.2) lib/ecto/adapters/sql.ex:1098: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto_sql 3.13.2) lib/ecto/adapters/sql.ex:969: Ecto.Adapters.SQL.insert_all/9
Solution:
Like email: StreamData.repeatedly(fn -> "email#{System.unique_integer()}@example.com" end)
Jump to solution
6 Replies
ZachDaniel
ZachDaniel2mo ago
It likely comes from producing non unique data across your various tests Use System.unique_integer instead of sequence and see if that helps Like with `StreamData.repeatedly'
Failz
FailzOP2mo ago
there might be some generators with nested StreamData is this a DB sequence? https://hexdocs.pm/ash/3.5.25/Ash.Generator.html#sequence/3
ZachDaniel
ZachDaniel2mo ago
No it's a process local unique data generator Nested stream data is totally fine
Failz
FailzOP2mo ago
Can you clarify what is meant by stream data repeatedly?
Solution
ZachDaniel
ZachDaniel2mo ago
Like email: StreamData.repeatedly(fn -> "email#{System.unique_integer()}@example.com" end)
Failz
FailzOP2mo ago
ah ok, looking at my generators I have a lot of those too I took StreamData.repeatedly to mean StreamData repeatedly 🤦‍♂️ updated the generators as suggested, remove max_case:2 and set pool_size back to pool_size: System.schedulers_online() * 2 tests are running without dead locks AND faster. You're a wizard Harry!!

Did you find this page helpful?