Mix test fails in umbrella (Ecto, Phoenix): db couldn't be dropped

When I run mix test from within the umbrella directory of my ibGib app, it runs random_gib correctly (which doesn’t touch Ecto db), and then it fails with the following:

** (Mix) The database for IbGib.Data.Repo couldn't be dropped: ERROR (object_in_use): database "ib_gib_db_test" is being accessed by other users

There are 10 other sessions using the database.

I’ve looked at a very similar looking issue that was recently fixed, and I tried adding my aliases in the umbrella project but with the same results (the above failure). Like that issue, If I run each of the other two apps individually (ib_gib or web_gib), then each runs successfully.

Running them individually is my current workaround and not a huge deal, but it would be nice to just run it once in the umbrella app. Any ideas?

Here are some env details:
Elixir -v: Elixir 1.3.1
Erlang/OTP 19 [erts-8.0] [source-6dc93c1] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
Postgres is 9.5.3 running in a docker container (shouldn’t matter)
Ubuntu Xenial

@ibgib: Please make sure that you have different database for test environment in your project configuration.
Database could not be accessed if it’s still used (as error says). It could be caused on some similar ways. One of your projects could have already opened connection to that database or you are connected to it from database CLI interface or another program manage your databases.

1 Like

@Eiji Thanks for your interest in this issue.

I do have it setup with two different test environments. Here are the two different test.exs files:

  • ib_gib
config :ib_gib, IbGib.Data.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "postgres",
  password: "postgres",
  database: "ib_gib_db_test",
  hostname: "",
  port: 5432,
  pool: Ecto.Adapters.SQL.Sandbox
  • web_gib:
config :web_gib, WebGib.Data.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "postgres",
  password: "postgres",
  database: "web_gib_test",
  hostname: "",
  port: 5432,
  pool: Ecto.Adapters.SQL.Sandbox

I just ran it again (haven’t in a LOOONG time), and the same results:


Finished in 0.2 seconds
19 tests, 0 failures

Randomized with seed 718378
** (Mix) The database for IbGib.Data.Repo couldn't be dropped: ERROR (object_in_use): database "ib_gib_db_test" is being accessed by other users

There are 10 other sessions using the database.

Still good ideas, but I don’t think either apply. Also, if that were the case, why would the tests work when executed individually inside the projects but only hang when executed from within the umbrella root folder?

@ibgib: Are these tests have async set to true? Maybe you have two tests that can’t be started at same time.
Can you share minimal code example of failing tests? It’s a little hard to tell what’s going wrong without try it myself.

1 Like

I did have many tests with async set to true, but just now I tried it with all of them set to false and I get the same results.

The entire codebase is open source here. I can tell you that the successful 19 tests are from random_gib (a helper library), and that web_gib does indeed use the test database for ib_gib, so the two applications would need to run separately from each other.

As for the minimal code example, I’m just not sure it’s worth it to try to troubleshoot the issue when executing the applications separately suffices. I posted mainly because I figured others would either say “yes, we’ve seen that problem with umbrella apps” or “no, my umbrella apps work fine running tests from the root directory”.

@ibgib: Open Source codebase is good too :slight_smile:
I will take a look at it today.

1 Like

@ibgib: I have lots of errors, for example: ** (DBConnection.ConnectionError) tcp connect: network is unreachable - :enetunreach. I can see that for dev environment you set database hostname to: and this looks like not work.
Can you describe minimal steps to just run mix test? I saw README.md and prepare all things like compile docker and setup mailgun - i.e. things that I don’t used yet could take me some time …

@Eiji Thanks for your persistence! :smile:

How familiar are you with docker? If you run a docker ps command, does it show something like this?

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
1d36e31b3905        postgres            "/docker-entrypoin..."   2 months ago        Up 7 hours          5432/tcp            postgres-ctr

Are you able to psql into the container with docker run -it --rm --link postgres-ctr:postgres postgres psql -d ib_gib_db_dev -h postgres -U postgres? Do you have psql installed? Also, which OS are you on? I’m on Ubuntu 16.04. Are you able to ping the container? Can you do a docker inspect on the container?

If your docker container is running, did you get the connection errors when running mix ecto.create and mix ecto.migrate in the ib_gib and web_gib folders?

I tried to be comprehensive on the exact steps required to get it up and going, so that is why I’m focused on the docker aspect as that may be what the hiccup is as I left that up to the docker install instructions.

I’ve gone ahead and made an issue, as I’m never sure of forum etiquette and it feels like I would be spamming the forum to get you up and going! I’ll be glad to give you any assistance I can though. :thumbsup:

The forum is for discussion of things just like this (although maybe in a new topic with a title specific about ibgib if this is what it is about?), so anywhere. :slight_smile:

1 Like

Yeah, that’s my point. This thread is about executing mix test in an umbrella’s root directory. But it’s moving into troubleshooting ibgib up and running, which I was thinking about offloading to the repo.

1 Like

@ibgib: Sorry for late reply I really need to take rest.

I don’t have a docker yet (never needed to use it before). If there are no other way to simple run tests then I will try to prepare docker, but I could take me some time. I have source-based distro, so I need to compile it with dependencies like GO language.

Yes, but not in/with docker.

Is it possible to run tests outside of docker? Anyway how about configuration that I mentioned?
What I tried before was:

  1. fetch sources by git
  2. comment out line: import_config "dev.secret.exs", because as you described in readme there will be a mailgun credentials that I do not need to check database, did I?
  3. tried to run mix test

As above I will setup docker, but it will take me some time, so if there is any way to run tests without it then please describe them.

1 Like

Rest is good. :smile:

I’m not sure if Docker is necessary, no. I certainly wasn’t anticipating a necessity to build from source. AFAIK, you only need to point your instance of postgres in the config, and then run the mix ecto.create/migrate commands.

Correct, this should be unnecessary to run the tests. I don’t automate any tests that touch mailgun (It’s too unreliable even in production!). I don’t think there is anything else in that secret file…or is there? :spy: (Seriously you can just comment it out)

@ibgib: Please comment/remove test alias in file: ib_gib_umb/apps/ib_gib/mix.exs and run tests again.


Awesome work @Eiji :smiley: :champagne:

You spotted it very quickly once we had you up and going! :+1:

1 Like