From bedce7f0e762b27520f8bb2d5655eeff02b849f5 Mon Sep 17 00:00:00 2001 From: yakimka Date: Mon, 28 Mar 2022 00:19:26 +0300 Subject: [PATCH 1/5] Update build badge in README.rst --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 855d6624..09295f92 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,8 @@ testcontainers-python ===================== -.. image:: https://travis-ci.org/testcontainers/testcontainers-python.svg?branch=master - :target: https://travis-ci.org/testcontainers/testcontainers-python +.. image:: https://github.com/testcontainers/testcontainers-python/workflows/testcontainers-python/badge.svg + :target: https://github.com/testcontainers/testcontainers-python/actions/workflows/main.yml .. image:: https://img.shields.io/pypi/v/testcontainers.svg?style=flat-square :target: https://pypi.python.org/pypi/testcontainers .. image:: https://readthedocs.org/projects/testcontainers-python/badge/?version=latest From cfc254159017ed5f2dcf360f7163060eeac0dbb5 Mon Sep 17 00:00:00 2001 From: yakimka Date: Mon, 28 Mar 2022 00:20:25 +0300 Subject: [PATCH 2/5] Delete extra `WORKDIR` from Dockerfile --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f839d68a..fb4ad5d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,6 @@ RUN pip install --upgrade pip \ && apt-get install -y \ freetds-dev \ && rm -rf /var/lib/apt/lists/* -WORKDIR /workspace ARG version=3.8 COPY requirements/${version}.txt requirements.txt COPY setup.py README.rst ./ From 8e1490df150d63c2cb4c428874fb6337643cc613 Mon Sep 17 00:00:00 2001 From: yakimka Date: Mon, 28 Mar 2022 00:21:25 +0300 Subject: [PATCH 3/5] Fix error when running `Neo4jContainer` failed by timeout --- testcontainers/neo4j.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/testcontainers/neo4j.py b/testcontainers/neo4j.py index f2e6ce72..5780db20 100644 --- a/testcontainers/neo4j.py +++ b/testcontainers/neo4j.py @@ -13,7 +13,6 @@ import os -import re import time from neo4j import GraphDatabase @@ -71,10 +70,13 @@ def get_connection_url(self): @wait_container_is_ready() def _connect(self): deadline = time.time() + Neo4jContainer.NEO4J_STARTUP_TIMEOUT_SECONDS - regex = re.compile("Remote interface available at", re.MULTILINE).search # First we wait for Neo4j to say it's listening - wait_for_logs(self, regex, Neo4jContainer.NEO4J_STARTUP_TIMEOUT_SECONDS) + wait_for_logs( + self, + "Remote interface available at", + Neo4jContainer.NEO4J_STARTUP_TIMEOUT_SECONDS / 4, + ) # Then we actually check that the container really is listening while time.time() < deadline: From ba3fdd8bc7a2605dbdda7d664fbbe13462d5d697 Mon Sep 17 00:00:00 2001 From: yakimka Date: Mon, 28 Mar 2022 00:25:27 +0300 Subject: [PATCH 4/5] Fix connect function in `RedisContainer` --- testcontainers/redis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testcontainers/redis.py b/testcontainers/redis.py index a8007d59..3b1fc5c2 100644 --- a/testcontainers/redis.py +++ b/testcontainers/redis.py @@ -27,7 +27,7 @@ def __init__(self, image="redis:latest", port_to_expose=6379): def _connect(self): client = self.get_client() if not client.ping(): - raise Exception + raise redis.exceptions.ConnectionError("Could not connect to Redis") def get_client(self, **kwargs): """get redis client From b64afbce46d439cf13491fc07c7b56a0efbde409 Mon Sep 17 00:00:00 2001 From: yakimka Date: Thu, 31 Mar 2022 00:26:24 +0300 Subject: [PATCH 5/5] Refactor `Neo4jContainer._connect` method --- testcontainers/neo4j.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/testcontainers/neo4j.py b/testcontainers/neo4j.py index 5780db20..b1887de2 100644 --- a/testcontainers/neo4j.py +++ b/testcontainers/neo4j.py @@ -13,10 +13,8 @@ import os -import time from neo4j import GraphDatabase -from testcontainers.core.exceptions import TimeoutException from testcontainers.core.generic import DbContainer from testcontainers.core.waiting_utils import wait_container_is_ready, wait_for_logs @@ -69,27 +67,19 @@ def get_connection_url(self): @wait_container_is_ready() def _connect(self): - deadline = time.time() + Neo4jContainer.NEO4J_STARTUP_TIMEOUT_SECONDS - # First we wait for Neo4j to say it's listening wait_for_logs( self, "Remote interface available at", - Neo4jContainer.NEO4J_STARTUP_TIMEOUT_SECONDS / 4, + Neo4jContainer.NEO4J_STARTUP_TIMEOUT_SECONDS, ) # Then we actually check that the container really is listening - while time.time() < deadline: - with self.get_driver() as driver: - # Drivers may or may not be lazy - # force them to do a round trip to confirm neo4j is working - with driver.session() as session: - session.run("RETURN 1").single() - return - - raise TimeoutException( - "Neo4j did not start within %.3f seconds" % Neo4jContainer.NEO4J_STARTUP_TIMEOUT_SECONDS - ) + with self.get_driver() as driver: + # Drivers may or may not be lazy + # force them to do a round trip to confirm neo4j is working + with driver.session() as session: + session.run("RETURN 1").single() def get_driver(self, **kwargs): return GraphDatabase.driver(