Testing with Ash fail

Hi guys I'm using Ash Framework in my Elixir project, and I have several tests that depend on a relatively complex seeding process. My seeding logic involves ( using setup to run before each step ) : Calling a custom fixture module that creates a lot of entities. Using Ash.bulk_create and other Ash APIs to populate the database. Here’s the issue I’m facing: When I run each test individually, all of them pass without any problem. However, when I run all tests together — even with async: false — only one test succeeds and the rest fail , For context: All tests use the same Repo and Ash resources. I run them with async: false (so concurrency shouldn’t be the issue). ( runningthem with async: true don't fix it either ) Each test calls the seeding logic in its setup. The seeds include multiple Ash.bulk_create operations. What I’d like to understand is: Is there an Ash-specific way (besides Ecto sandboxing) to ensure each test starts with a clean state when using bulk operations and fixtures? and thanks a lot in advance :Prayge:
12 Replies
ZachDaniel
ZachDaniel2mo ago
Ecto sandboxing is the only way What you're doing typically works OOTB
Makarov
MakarovOP2mo ago
Ecto sandboxing each test you mean ? Cause when i run each test independtly ( comment out other tests ) it works ! I actually forgot to mention that the tests use phoenix liveview test utilities ( render submit , and forms )
ZachDaniel
ZachDaniel2mo ago
That should be fine, but yes you should be using the ecto sandbpx Are you?
Makarov
MakarovOP2mo ago
Yes i do , ig it s the default ( in the pool: option )
ZachDaniel
ZachDaniel2mo ago
Have you set config :ash, :disable_async?, true in test
Makarov
MakarovOP2mo ago
Yes ! in config/test.exs
ZachDaniel
ZachDaniel2mo ago
Hm....honestly nothing comes to mind How are the other tests failing
Makarov
MakarovOP2mo ago
the test basically do this : - visit a path using get() and live() - view |> render_submit() for forms . this works when running tests independently , but for some reason it fails when runiing everything 😂 , there is also two setup , one for regustring and login in some user , and the other is for seeding database with different entities !
ZachDaniel
ZachDaniel2mo ago
Right, but "works" and "doesn't work" is not super helpful How do the tests fail? What is the failure? What data layer do they use? Stuff like that
Makarov
MakarovOP2mo ago
Thanks a lot mate , i understand , you re perfectly right ! Well by fail some assertion fails , i assert that some data that was supposed to be inserted exists ( which doesn't when there is many tests 🤓 ) i altered slightly the code here : inside both tests , there is something like this . We insert an element B that belongs to A ( defined in the resource ) .
conn = insert_B(conn, A)
A = get_A(id)
assert Enum.count(A.B) == 1
conn = insert_B(conn, A)
A = get_A(id)
assert Enum.count(A.B) == 1
and thanks a lot again 🙏 !
ZachDaniel
ZachDaniel2mo ago
The data not existing sounds strange Not like a sandboxing issue IMO
Makarov
MakarovOP2mo ago
Yes , i added Process.sleep(5000) ( big i know ) just to see if it's a db related error , but still the same ! ig i need to make some illustration for the error 😅

Did you find this page helpful?