testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

Add functionality to wait till mongo container becomes available

Open smparekh opened this issue 5 years ago • 5 comments

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.

smparekh avatar Mar 30 '20 03:03 smparekh

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

smparekh avatar Mar 30 '20 06:03 smparekh

@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 avatar Apr 03 '20 04:04 smparekh

@smparekh, I don't have the privileges to restart a build, unfortunately. Force-pushing may retrigger the build, however.

tillahoffmann avatar Apr 03 '20 09:04 tillahoffmann

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) ====================================================================

smparekh avatar Apr 03 '20 10:04 smparekh

@tillahoffmann, was finally able to build and test via Travis, if you could take a look that would be great.

smparekh avatar May 27 '20 20:05 smparekh

thank you @smparekh for your contribution - we are favoring log based waiting now, so im closing this in favor of #461

alexanderankin avatar Mar 09 '24 15:03 alexanderankin