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
Ecto sandboxing is the only way
What you're doing typically works OOTB
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 )
That should be fine, but yes you should be using the ecto sandbpx
Are you?
Yes i do , ig it s the default ( in the pool: option )
Have you set
config :ash, :disable_async?, true in testYes ! in config/test.exs
Hm....honestly nothing comes to mind
How are the other tests failing
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 !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
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 ) .
and thanks a lot again 🙏 !
The data not existing sounds strange
Not like a sandboxing issue IMO
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 😅