Skip to content

Commit 1106e3b

Browse files
committed
Avoid test failures, and document the bug in Docker Desktop for Windows that was causing them.
1 parent e52150c commit 1106e3b

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

README.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ We recommend you use a `virtual environment <https://virtualenv.pypa.io/en/stabl
7676
7777
Note, the anonymous tier of Docker Hub rate limits downloads to 100 container image requests per six hours, and running all of the tests in the tests directory for the first time appears to exceed the limit.
7878

79-
Also, the SQL Server tests will fail unless you have Microsoft ODBC Driver 17 for SQL Server installed, available from https://docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server.
79+
The SQL Server tests will fail unless you have Microsoft ODBC Driver 17 for SQL Server installed, available from https://docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server.
80+
81+
There is an apparent bug in Docker Desktop for Windows, described at https://github.com/docker/docker-py/issues/2792, that causes the DockerContainer.getExposedPort() method to fail if it is called immediately after starting the container. Some of the test cases implement a 5 second time timeout to avoid hitting this bug.
8082

8183
Adding requirements
8284
^^^^^^^^^^^^^^^^^^^

tests/test_db_containers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def test_docker_run_neo4j_latest():
130130

131131
def test_docker_generic_db():
132132
mongo_container = DockerContainer("mongo:latest")
133-
mongo_container.with_bind_ports(27017, 27017)
133+
mongo_container.with_exposed_ports(27017)
134134

135135
with mongo_container:
136136
def connect():

tests/test_kafka.py

+4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
from testcontainers.kafka import KafkaContainer
44

5+
import time
6+
57

68
def test_kafka_producer_consumer():
79
with KafkaContainer() as container:
10+
time.sleep(5)
811
produce_and_consume_kafka_message(container)
912

1013

1114
def test_kafka_producer_consumer_custom_port():
1215
with KafkaContainer(port_to_expose=9888) as container:
16+
time.sleep(5)
1317
assert container.port_to_expose == 9888
1418
produce_and_consume_kafka_message(container)
1519

tests/test_new_docker_api.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import re
33
from pathlib import Path
4+
import time
45

56
from testcontainers import mysql
67

@@ -19,6 +20,7 @@ def test_docker_custom_image():
1920
container.with_env("MYSQL_ROOT_PASSWORD", "root")
2021

2122
with container:
23+
time.sleep(5)
2224
port = container.get_exposed_port(3306)
2325
assert int(port) > 0
2426

tests/test_nginx_container.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
def test_docker_run_nginx():
88
nginx_container = NginxContainer("nginx:1.13.8")
99
with nginx_container as nginx:
10+
time.sleep(5)
1011
port = nginx.port_to_expose
1112
url = "http://{}:{}/".format(nginx.get_container_host_ip(),
1213
nginx.get_exposed_port(port))
13-
time.sleep(5)
1414
r = requests.get(url)
1515
assert(r.status_code == 200)
1616
assert('Welcome to nginx!' in r.text)

0 commit comments

Comments
 (0)