mix-test.watch icon indicating copy to clipboard operation
mix-test.watch copied to clipboard

Database couldn't be dropped

Open cospin opened this issue 4 years ago • 10 comments

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?

cospin avatar Jan 25 '20 02:01 cospin

Could you share a minimal preproduction of the issue please? Thanks.

lpil avatar Jan 26 '20 12:01 lpil

@CristianOspina take a look at this article, maybe it will help solve your problem

https://medium.com/@a4word/continuous-testing-with-elixir-ddc1107c5cc0

anzaika avatar Jan 30 '20 21:01 anzaika

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?

cospin avatar Jan 31 '20 06:01 cospin

Could you share your mix.exs file please? Hard to help without any of the details. Thank you.

lpil avatar Jan 31 '20 09:01 lpil

Sure: mix.exs application.ex

cospin avatar Jan 31 '20 19:01 cospin

Can you share the bits of your config.exs where you configure your database? Thanks

lpil avatar Jan 31 '20 19:01 lpil

Here

cospin avatar Jan 31 '20 19:01 cospin

I can't obviously see the problem I'm afraid. Perhaps someone with more familiarity with ecto may be able to help.

lpil avatar Jan 31 '20 20:01 lpil

facing the same issue as described by @CristianOspina

@CristianOspina Could you please explain how you meant to use test.once as a workaround?

dyyce avatar Mar 25 '20 07:03 dyyce

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?

cospin avatar Mar 25 '20 10:03 cospin