Skip to content

Commit

Permalink
Wait for the port to become available instead of the application.
Browse files Browse the repository at this point in the history
  • Loading branch information
seancribbs committed Jul 16, 2012
1 parent 509af28 commit 9a84189
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/pb_service_test.erl
Expand Up @@ -86,6 +86,7 @@ setup() ->
riak_api_pb_service:register(?MODULE, ?MSGMIN, ?MSGMAX),

[ application:start(A) || A <- Deps ],
wait_for_port(),
{OldServices, OldHost, OldPort, Deps}.

cleanup({S, H, P, Deps}) ->
Expand Down Expand Up @@ -164,6 +165,36 @@ late_registration_test_() ->
end)
}.

wait_for_port() ->
wait_for_port(10000).

wait_for_port(Timeout) when is_integer(Timeout) ->
lager:debug("Waiting for PB Port within timeout ~p", [Timeout]),
TRef = erlang:send_after(Timeout, self(), timeout),
wait_for_port(TRef);
wait_for_port(TRef) ->
Me = self(),
erlang:spawn(fun() ->
case new_connection() of
{ok, Socket} ->
gen_tcp:close(Socket),
Me ! connected;
{error, Reason} ->
Me ! {error, Reason}
end
end),
receive
timeout ->
lager:error("PB port did not come up within timeout"),
{error, timeout};
{error, Reason} ->
lager:debug("Waiting for PB port failed: ~p", [Reason]),
wait_for_port(TRef);
connected ->
erlang:cancel_timer(TRef),
lager:debug("PB port is up"),
ok
end.

wait_for_application_shutdown(App) ->
case lists:keymember(App, 1, application:which_applications()) of
Expand Down

0 comments on commit 9a84189

Please sign in to comment.