Add functionality to wait till mongo container becomes available
Replicates the wait functionality available in the redis module, during the use of current version ran into an issue with mongo:4 where it was taking a little longer to start the container before pytest ran the unit tests. Currently, I have had to add code to wait for log statements as such:
@pytest.fixture(scope="session")
def test_client():
# init mongo
mongo_container = MongoDbContainer("mongo:4").start()
wait_for_logs(mongo_container, 'waiting for connections on port 27017')
...
but I believe the container should wait on start for it to finish spawning.
Tests are failing because of:
E docker.errors.ImageNotFound: 404 Client Error: Not Found ("No such image: hello-world:latest")
for all python versions, it might have been a connection issue to Docker Hub, rerequesting the build run
@tillahoffmann , any chance you can rerun the travis build? I can't seem to kick it off, hopefully the image pull issue is fixed
@smparekh, I don't have the privileges to restart a build, unfortunately. Force-pushing may retrigger the build, however.
Not sure why build is failing on travis, I ran the tests locally for python 3.7 as a sanity check and the test in question passes:
tests/test_core.py::test_wait_for_hello
Pulling image hello-world
⠋
Container started: 2088cf603a
PASSED
in fact all tests pass:
---------- coverage: platform darwin, python 3.7.7-final-0 -----------
Name Stmts Miss Branch BrPart Cover
------------------------------------------------------------------------
testcontainers/core/container.py 76 5 10 4 90%
testcontainers/core/docker_client.py 12 2 0 0 83%
testcontainers/core/utils.py 21 10 6 0 41%
testcontainers/core/waiting_utils.py 33 1 8 2 93%
testcontainers/elasticsearch.py 23 1 2 1 92%
testcontainers/general.py 7 7 2 0 0%
testcontainers/google/pubsub.py 22 0 2 1 96%
testcontainers/mongodb.py 29 5 0 0 83%
testcontainers/mysql.py 31 5 12 6 74%
testcontainers/oracle.py 9 4 0 0 56%
testcontainers/redis.py 18 1 2 1 90%
testcontainers/selenium.py 27 2 2 1 90%
------------------------------------------------------------------------
TOTAL 393 43 50 16 85%
9 files skipped due to complete coverage.
Coverage HTML written to dir skip-covered
=================================================================== 20 passed, 1 skipped in 492.10s (0:08:12) ====================================================================
@tillahoffmann, was finally able to build and test via Travis, if you could take a look that would be great.
thank you @smparekh for your contribution - we are favoring log based waiting now, so im closing this in favor of #461