Closed GenericJam closed 4 years ago
Hi @GenericJam! Can you please provide an application with the dockerfile that reproduces the error? The more specific you can be, the better. For example:
$ start_docker_container
$ curl address_n_times
Thank you!
I think the problem was trying to initialize the database at the wrong time during the application start up. This DB wrapper is run at start up by the main application.
I was doing it in test/test_helper.exs like so:
ExUnit.start()
Mix.Task.run("ecto.migrate")
DBImpl.reset_db()
DBImpl.populate_db()
DBImpl.create_releases()
Moving them to a conditional block in the init/1
of the database module solved the problem it seems. So now I'm testing to see which environment the code is in and running these if it's in testing.
The part that was sort of mystifying is running natively on OSX it was fine but in Docker it's not. Maybe being in two separate containers makes the problem more apparent.
I'm happy to close as this isn't a bug, more of a weird gotcha. Hopefully this can help someone if they run across the same sort of error. I'm not sure if the error message can be improved to say it's not ready yet or highlighting the wrong order is the problem.
Perhaps the documentation around what order things fire in when you run a test would be helpful.
mix test
is essentially just starting the app in the test environment as far as I understand, so this starts first? Then the test_helper.exs? Which starts ExUnit? My previous understanding was that this was the order so it seemed like the initial way would have worked.
This is super strange. Not having this error while running locally or while running releases in Docker. This error happens sometimes (1/4 or so runs) while running tests in docker. Two separate docker containers running Elixir and Postgres.
I thought it may be because Docker is caching so I pruned the docker images between runs and it still fails on the first run sometimes.
The migration runs but fails the first time the code tries to use the DB.
*Edit: Upon further inspection this is happening every* time but sometimes it will recover and finish running the tests and sometimes it completely fails.
Dockerfile:
docker-compose.xml: