Skip to content

Commit

Permalink
allow to set the timeout and retry interval when waiting for services.
Browse files Browse the repository at this point in the history
…Fixes #19
  • Loading branch information
dobe committed Aug 18, 2021
1 parent 9691915 commit df8567b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changes for Lovely Pytest Docker
unreleased
==========

- allow to set the timeout and retry interval when waiting for services
- added explicit dependency to six, which is no more required in newer pytest versions

2021/08/05 0.2.1
Expand Down
14 changes: 8 additions & 6 deletions src/lovely/pytest/docker/compose.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import functools
import os
import pytest
import re
import subprocess
import time
import timeit
import functools

import pytest
from six.moves.urllib.error import HTTPError
from six.moves.urllib.request import urlopen

Expand Down Expand Up @@ -84,7 +83,7 @@ def execute(self, service, *cmd):
"""
return self._docker_compose.execute('exec', '-T', service, *cmd)

def wait_for_service(self, service, private_port, check_server=check_url):
def wait_for_service(self, service, private_port, check_server=check_url, timeout=30.0, pause=0.1):
"""
Waits for the given service to response to a http GET.
Expand All @@ -93,12 +92,15 @@ def wait_for_service(self, service, private_port, check_server=check_url):
:param check_server: optional function to check if the server is ready
(default check method makes GET request to '/'
of HTTP endpoint)
:param timeout: maximum time to wait for the service in seconds
:param pause: time in seconds to wait between retries
:return: the public port of the service exposed to host system if any
"""
public_port = self.port_for(service, private_port)
self.wait_until_responsive(
timeout=30.0,
pause=0.1,
timeout=timeout,
pause=pause,
check=lambda: check_server(self.docker_ip, public_port),
)
return public_port
Expand Down

0 comments on commit df8567b

Please sign in to comment.