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

pb_service_test no longer runs #36

Merged
merged 3 commits into from
Oct 1, 2013
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
Binary file added rebar
Binary file not shown.
61 changes: 10 additions & 51 deletions test/pb_service_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,29 @@ process_stream(_, _, State) ->
%% Eunit tests
%% ===================================================================
setup() ->
Deps = resolve_deps(riak_api), %% Implicitly loads apps
application:load(lager),
application:load(riak_api),

application:set_env(sasl, sasl_error_logger, {file, "pb_service_test_sasl.log"}),
error_logger:tty(false),
error_logger:logfile({open, "pb_service_test.log"}),

application:set_env(lager, handlers, [{lager_file_backend, [{"pb_service_test.log", debug, 10485760, "$D0", 5}]}]),
application:set_env(lager, error_logger_redirect, true),

application:set_env(riak_core, handoff_port, 0),

OldListeners = app_helper:get_env(riak_api, pb, [{"127.0.0.1", 8087}]),
application:set_env(riak_api, pb, [{"127.0.0.1", 32767}]),

[ application:start(A) || A <- Deps ],
riak_core:wait_for_application(riak_api),
lager:start(),
{ok, Sup} = riak_api_sup:start_link(),
unlink(Sup),
wait_for_port(),
riak_api_pb_service:register(?MODULE, ?MSGMIN, ?MSGMAX),
riak_api_pb_service:register(?MODULE, 111),
{OldListeners, Deps}.
{OldListeners, Sup}.


cleanup({L, Deps}) ->
[ application:stop(A) || A <- lists:reverse(Deps), not is_otp_base_app(A) ],
wait_for_application_shutdown(riak_api),
cleanup({L, Sup}) ->
exit(Sup, normal),
application:set_env(riak_api, pb, L),
application:stop(lager),
ok.

request_multi(Payloads) when is_list(Payloads) ->
Expand Down Expand Up @@ -270,42 +268,3 @@ wait_for_port(TRef) ->
lager:debug("PB port is up"),
ok
end.

wait_for_application_shutdown(App) ->
case lists:keymember(App, 1, application:which_applications()) of
true ->
timer:sleep(250),
wait_for_application_shutdown(App);
false ->
ok
end.

%% The following three functions build a list of dependent
%% applications. They will not handle circular or mutually-dependent
%% applications.
dep_apps(App) ->
application:load(App),
{ok, Apps} = application:get_key(App, applications),
Apps.

all_deps(App, Deps) ->
[[ all_deps(Dep, [App|Deps]) || Dep <- dep_apps(App),
not lists:member(Dep, Deps)], App].

resolve_deps(App) ->
DepList = all_deps(App, []),
{AppOrder, _} = lists:foldl(fun(A,{List,Set}) ->
case sets:is_element(A, Set) of
true ->
{List, Set};
false ->
{List ++ [A], sets:add_element(A, Set)}
end
end,
{[], sets:new()},
lists:flatten(DepList)),
AppOrder.

is_otp_base_app(kernel) -> true;
is_otp_base_app(stdlib) -> true;
is_otp_base_app(_) -> false.
41 changes: 41 additions & 0 deletions test/riak_api_test_util.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-module(riak_api_test_util).
-compile(export_all).

wait_for_application_shutdown(App) ->
case lists:keymember(App, 1, application:which_applications()) of
true ->
timer:sleep(250),
wait_for_application_shutdown(App);
false ->
ok
end.

%% The following three functions build a list of dependent
%% applications. They will not handle circular or mutually-dependent
%% applications.
dep_apps(App) ->
application:load(App),
{ok, Apps} = application:get_key(App, applications),
Apps.

all_deps(App, Deps) ->
[[ all_deps(Dep, [App|Deps]) || Dep <- dep_apps(App),
not lists:member(Dep, Deps)], App].

resolve_deps(App) ->
DepList = all_deps(App, []),
{AppOrder, _} = lists:foldl(fun(A,{List,Set}) ->
case sets:is_element(A, Set) of
true ->
{List, Set};
false ->
{List ++ [A], sets:add_element(A, Set)}
end
end,
{[], sets:new()},
lists:flatten(DepList)),
AppOrder.

is_otp_base_app(kernel) -> true;
is_otp_base_app(stdlib) -> true;
is_otp_base_app(_) -> false.