Dockerpy测试容器在数据库可用之前超时?

时间:2017-05-06 13:38:40

标签: python docker neo4j python-unittest dockerpy

我在Docker容器中加载了一个数据库(Neo4J),但我认为我的单元测试会在加载数据库之前点击容器。

def setUp(self):
    client = docker.from_env()
    self.container = client.containers.run("neo4j",
        detach=True,
        environment={'NEO4J_AUTH':'none'},
        ports={7474:7474, 7687:7687},
        volumes={'/Users/myuser/neo4j/data': {'bind': '/data', 'mode': 'rw'}}
    )
    self.container.start()

def test_database_loads(self):
    r = requests.get(self.database_url)
    self.assertEqual(r.status_code, 400)

我收到此错误:

======================================================================
ERROR: test_database_loads (backend.api.tests.test_base.BaseTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/aljabear/.pyenv/versions/visualist/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 386, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/Users/aljabear/.pyenv/versions/visualist/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 382, in _make_request
    httplib_response = conn.getresponse()
  File "/Users/aljabear/.pyenv/versions/3.5.3/lib/python3.5/http/client.py", line 1198, in getresponse
    response.begin()
  File "/Users/aljabear/.pyenv/versions/3.5.3/lib/python3.5/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/Users/aljabear/.pyenv/versions/3.5.3/lib/python3.5/http/client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/Users/aljabear/.pyenv/versions/3.5.3/lib/python3.5/socket.py", line 576, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

...等。基本上我的请求超时了。

我认为我的环境还可以;如果我让容器继续运行,我可以稍后通过curl访问它。

我的预感是我在Neo4J开始之前正在ping容器。有没有办法强制Dockerpy等到容器托管的脚本启动并运行?

由于

0 个答案:

没有答案