Skip to content

Commit

Permalink
refactor port wait strategy + strategy execution
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlah committed Oct 15, 2023
1 parent 9940c4d commit 39748dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 9 additions & 2 deletions lib/docker/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ defmodule Testcontainers.Docker.Api do
:ok <-
if(!Enum.empty?(wait_strategies),
do:
Enum.each(wait_strategies, fn wait_strategy ->
WaitStrategy.wait_until_container_is_ready(wait_strategy, container.container_id)
Enum.reduce(wait_strategies, :ok, fn
wait_strategy, :ok ->
WaitStrategy.wait_until_container_is_ready(
wait_strategy,
container.container_id
)

_, error ->
error
end),
else: :ok
) do
Expand Down
16 changes: 10 additions & 6 deletions lib/wait_strategy/port_wait_strategy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ defimpl Testcontainers.WaitStrategy, for: Testcontainers.WaitStrategy.PortWaitSt
with {:ok, %Container{} = container} <- Docker.Api.get_container(id_or_name) do
host_port = Container.mapped_port(container, wait_strategy.port)

case wait_for_port(wait_strategy.ip, host_port, wait_strategy.timeout) do
{:ok, :port_is_open} ->
:ok
if host_port == nil do
{:error, {:no_host_port, wait_strategy.port}}
else
case wait_for_port(wait_strategy.ip, host_port, wait_strategy.timeout) do
{:ok, :port_is_open} ->
:ok

_ ->
:timer.sleep(100)
wait_until_container_is_ready(wait_strategy, id_or_name)
_ ->
:timer.sleep(100)
wait_until_container_is_ready(wait_strategy, id_or_name)
end
end
end
end
Expand Down

0 comments on commit 39748dc

Please sign in to comment.