mix-test.watch
mix-test.watch copied to clipboard
Database couldn't be dropped
Hello, I get this error:
$ mix test.watch
Running tests...
** (Mix) The database for App.Repo couldn't be dropped:
ERROR 55006 (object_in_use): database "app_test" is
being accessed by other users
There are 10 other sessions using the database.
mix test
works fine. Do you know what could it be?
Could you share a minimal preproduction of the issue please? Thanks.
@CristianOspina take a look at this article, maybe it will help solve your problem
https://medium.com/@a4word/continuous-testing-with-elixir-ddc1107c5cc0
Sorry for the delay @lpil, for now is hard to know how to reproduce. Tried to isolate some things but the problem still persist.
With one workaround in the article that @anzaika give me (thanks!) it works fine. Jus needed to reeplace the mix alias "test"
for "test.once"
(or anything). This made the "test" command to not clean the database, something that I really need to do for the tests, but can live with it for now.
So the issue seems to be that somewhere in my app the database is starting before test.watch
runs the test
command, any advice on how to debug this?
Could you share your mix.exs file please? Hard to help without any of the details. Thank you.
Sure: mix.exs application.ex
Can you share the bits of your config.exs where you configure your database? Thanks
I can't obviously see the problem I'm afraid. Perhaps someone with more familiarity with ecto may be able to help.
facing the same issue as described by @CristianOspina
@CristianOspina
Could you please explain how you meant to use test.once
as a workaround?
Hey @dyyce, in your mix.exs
(example here) add this to project: preferred_cli_env: ["test.once": :test]
. Then in aliases duplicate the test
alias, comment the original and replace the name in the second one for: "test.once"
. Now you can use mix test.watch
, and if you want to test as always you need to use mix test.once
insted of mix test.
You can change test.once for whatever string you want.
As this workaround is for dev, I haven't commited those changes to the repo, they are just local. It will break CI/CD etc.
Btw, could you also post your mix.exs
and application.ex
to compare and try to get some clue about this error?