Skip to content

Commit

Permalink
fixup! Fix: Race condition in DockerContainerTestCase (#6587)
Browse files Browse the repository at this point in the history
  • Loading branch information
achave11-ucsc committed Sep 27, 2024
1 parent 1cb840b commit 841f1e6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions test/docker_container_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ def _create_container(cls, image: str, container_port: int, **kwargs) -> Netloc:
log.info('Launching %scontainer from image %s',
'sibling ' if is_sibling else '', image)
ports = None if is_sibling else {container_port: ('127.0.0.1', None)}
start = datetime.now()
container = cls._docker.containers.run(image,
detach=True,
auto_remove=True,
ports=ports,
**kwargs)
try:
time_it = datetime.now()
container_info = cls._docker.api.inspect_container(container.id)
if is_sibling: # no coverage
container_ip = container_info['NetworkSettings']['IPAddress']
Expand All @@ -94,8 +94,8 @@ def _create_container(cls, image: str, container_port: int, **kwargs) -> Netloc:
log.info('Launched sibling container %s from image %s, listening on %s:%i',
container.name, image, container_ip, container_port)
else:
seconds = 0.0
while True:
seconds = (datetime.now() - start).total_seconds()
ports = container_info['NetworkSettings']['Ports'][f'{container_port}/tcp']
if len(ports) > 0:
break
Expand All @@ -104,7 +104,6 @@ def _create_container(cls, image: str, container_port: int, **kwargs) -> Netloc:
else:
time.sleep(.33)
container_info = cls._docker.api.inspect_container(container.id)
seconds = (datetime.now() - time_it).total_seconds()
port = one(ports)
host_ip = port['HostIp']
host_port = int(port['HostPort'])
Expand Down

0 comments on commit 841f1e6

Please sign in to comment.