Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start probes in parallel #523

Merged
merged 3 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions goth/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,29 @@ async def _start_nodes(self):
node_names: Dict[str, str] = {}
ports: Dict[str, dict] = {}

# Start the probes' containers and obtain their IP addresses
# Start all probes as asyncio tasks in parallel, cancel them on error
probe_tasks = [
asyncio.create_task(self._exit_stack.enter_async_context(run_probe(probe)))
for probe in self.probes
]
try:
future_gather = asyncio.gather(*probe_tasks)
await future_gather
except Exception as e:
for task in probe_tasks:
task.cancel()
logger.error(f"Starting probes failed: {e!r}")
raise e

# Obtain the probes' IP addresses and port mappings
for probe in self.probes:
ip_address = await self._exit_stack.enter_async_context(run_probe(probe))
node_names[ip_address] = probe.name
node_names[probe.ip_address] = probe.name
container_ports = probe.container.ports
ports[ip_address] = container_ports
ports[probe.ip_address] = container_ports
logger.debug(
"Probe for %s started on IP: %s with port mapping: %s",
"Probe for %s started. IP address: %s, port mapping: %s",
probe.name,
ip_address,
probe.ip_address,
container_ports,
)

Expand Down
5 changes: 4 additions & 1 deletion goth/runner/probe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@ def create_probe(

@contextlib.asynccontextmanager
async def run_probe(probe: Probe) -> AsyncIterator[str]:
"""Implement AsyncContextManager for starting and stopping a probe."""
"""Implement AsyncContextManager for starting and stopping a probe.

Yields the probe's assigned IP address.
"""

try:
logger.debug("Starting probe. name=%s", probe.name)
Expand Down
3 changes: 3 additions & 0 deletions test/goth/runner/test_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ async def _coro(*args):
)
@pytest.mark.asyncio
async def test_runner_startup_shutdown(
caplog,
mock_function,
manager_start_fails,
webserver_start_fails,
Expand Down Expand Up @@ -195,6 +196,8 @@ async def test_runner_startup_shutdown(
or probe_init.failed
or probe_start.failed
)
if proxy_start.failed:
assert "Starting probes failed: MockError" in caplog.text


@pytest.mark.parametrize("have_test_failure", [False, True])
Expand Down