testcontainers / testcontainers-python

Testcontainers is a Python library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.
https://testcontainers-python.readthedocs.io/en/latest/
Apache License 2.0
1.51k stars 281 forks source link

Bug: ElasticSearchContainer raises urllib.error.URLError during startup, which is not caught #560

Closed slahn closed 4 months ago

slahn commented 4 months ago

Describe the bug

The ElasticSearchContainer._connect method raises a urllib.error.URLError (wrapping a ConnectionRefusedError) when the container is not yet ready. This exception is not caught by the @wait_container_is_ready decorator.

Fixed by adding urllib.error.URLError to transient_exceptions parameter of @wait_container_is_ready decorator.

To Reproduce

from testcontainers.elasticsearch import ElasticSearchContainer

with ElasticSearchContainer(
    "docker.elastic.co/elasticsearch/elasticsearch:8.13.1"
) as elastic:
    print(elastic.get_url())

Runtime environment

$ uname -a
Darwin XXXXXXX 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 arm64
$ poetry run python --version
Python 3.12.3
$ poetry run pip freeze | grep testcon
testcontainers-core==0.0.1rc1
testcontainers-elasticsearch==0.0.1rc1
alexanderankin commented 4 months ago

we don't control these packages:

testcontainers-core==0.0.1rc1
testcontainers-elasticsearch==0.0.1rc1

you can install testcontainers[elasticsearch] - this is maintained. i think you will be able to test sooner than i can with the updated package.

slahn commented 4 months ago

Oh! I have no idea how we came to use the wrong packages, but thanks for letting me know.

This bug was fixed in commit 0f9ad24.

alexanderankin commented 4 months ago

I have no idea how we came to use...

We don't control those packages anymore