Skip to content

Commit 9100aaf

Browse files
authored
Fix flacky tests and improvements (#191)
* Update build badge in README.rst * Delete extra `WORKDIR` from Dockerfile * Fix error when running `Neo4jContainer` failed by timeout * Fix connect function in `RedisContainer` * Refactor `Neo4jContainer._connect` method
1 parent 3b8a1b5 commit 9100aaf

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ RUN pip install --upgrade pip \
77
&& apt-get install -y \
88
freetds-dev \
99
&& rm -rf /var/lib/apt/lists/*
10-
WORKDIR /workspace
1110
ARG version=3.8
1211
COPY requirements/${version}.txt requirements.txt
1312
COPY setup.py README.rst ./

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
testcontainers-python
22
=====================
33

4-
.. image:: https://travis-ci.org/testcontainers/testcontainers-python.svg?branch=master
5-
:target: https://travis-ci.org/testcontainers/testcontainers-python
4+
.. image:: https://github.com/testcontainers/testcontainers-python/workflows/testcontainers-python/badge.svg
5+
:target: https://github.com/testcontainers/testcontainers-python/actions/workflows/main.yml
66
.. image:: https://img.shields.io/pypi/v/testcontainers.svg?style=flat-square
77
:target: https://pypi.python.org/pypi/testcontainers
88
.. image:: https://readthedocs.org/projects/testcontainers-python/badge/?version=latest

testcontainers/neo4j.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313

1414
import os
1515

16-
import re
17-
import time
1816
from neo4j import GraphDatabase
1917

20-
from testcontainers.core.exceptions import TimeoutException
2118
from testcontainers.core.generic import DbContainer
2219
from testcontainers.core.waiting_utils import wait_container_is_ready, wait_for_logs
2320

@@ -70,24 +67,19 @@ def get_connection_url(self):
7067

7168
@wait_container_is_ready()
7269
def _connect(self):
73-
deadline = time.time() + Neo4jContainer.NEO4J_STARTUP_TIMEOUT_SECONDS
74-
regex = re.compile("Remote interface available at", re.MULTILINE).search
75-
7670
# First we wait for Neo4j to say it's listening
77-
wait_for_logs(self, regex, Neo4jContainer.NEO4J_STARTUP_TIMEOUT_SECONDS)
71+
wait_for_logs(
72+
self,
73+
"Remote interface available at",
74+
Neo4jContainer.NEO4J_STARTUP_TIMEOUT_SECONDS,
75+
)
7876

7977
# Then we actually check that the container really is listening
80-
while time.time() < deadline:
81-
with self.get_driver() as driver:
82-
# Drivers may or may not be lazy
83-
# force them to do a round trip to confirm neo4j is working
84-
with driver.session() as session:
85-
session.run("RETURN 1").single()
86-
return
87-
88-
raise TimeoutException(
89-
"Neo4j did not start within %.3f seconds" % Neo4jContainer.NEO4J_STARTUP_TIMEOUT_SECONDS
90-
)
78+
with self.get_driver() as driver:
79+
# Drivers may or may not be lazy
80+
# force them to do a round trip to confirm neo4j is working
81+
with driver.session() as session:
82+
session.run("RETURN 1").single()
9183

9284
def get_driver(self, **kwargs):
9385
return GraphDatabase.driver(

testcontainers/redis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, image="redis:latest", port_to_expose=6379):
2727
def _connect(self):
2828
client = self.get_client()
2929
if not client.ping():
30-
raise Exception
30+
raise redis.exceptions.ConnectionError("Could not connect to Redis")
3131

3232
def get_client(self, **kwargs):
3333
"""get redis client

0 commit comments

Comments
 (0)