aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2012-02-29 15:19:54 +0100
committerMicael Karlberg <[email protected]>2012-02-29 15:19:54 +0100
commit66288284701787c7b9e1775ec9bc91732c87f51d (patch)
treefbebd93cb70018893c154a7235973a1644cff702
parentfae2034ba30fd9936960418ba36b90ca7028bb3d (diff)
downloadotp-66288284701787c7b9e1775ec9bc91732c87f51d.tar.gz
otp-66288284701787c7b9e1775ec9bc91732c87f51d.tar.bz2
otp-66288284701787c7b9e1775ec9bc91732c87f51d.zip
[inets/httpc] Make inets tests behave on all IPv6 impl
Updated according to pan/inets_ipv6_test_issues as far as possible (that branch is based on master).
-rw-r--r--lib/inets/test/httpc_SUITE.erl44
-rw-r--r--lib/inets/test/httpd_SUITE.erl41
-rw-r--r--lib/inets/test/inets_test_lib.erl115
3 files changed, 107 insertions, 93 deletions
diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl
index 3484a36047..a18d079426 100644
--- a/lib/inets/test/httpc_SUITE.erl
+++ b/lib/inets/test/httpc_SUITE.erl
@@ -275,6 +275,20 @@ init_per_testcase(Case, Timeout, Config) ->
%% inets:enable_trace(max, io, httpc),
%% inets:enable_trace(max, io, all),
+ %% <IPv6>
+ % Set default ipfamily to the same as the main server has by default
+ %% This makes the client try w/ ipv6 before falling back to ipv4,
+ %% as that is what the server is configured to do.
+ %% Note that this is required for the tests to run on *BSD w/ ipv6 enabled
+ %% as well as on Windows. The Linux behaviour of allowing ipv4 connects
+ %% to ipv6 sockets is not required or even encouraged.
+
+ httpc:set_options([{ipfamily, inet6fb4}]),
+
+ %% Note that the IPv6 trest case *must* use inet6,
+ %% so this value will be overwritten (see "ipv6_" below).
+ %% </IPv6>
+
NewConfig =
case atom_to_list(Case) of
[$s, $s, $l | _] ->
@@ -376,16 +390,18 @@ init_per_testcase(Case, Timeout, Config) ->
_ ->
%% Try inet6fb4 on windows...
- tsp("init_per_testcase -> allways try IPv6 on windows"),
- ?RUN_ON_WINDOWS(
- fun() ->
- tsp("init_per_testcase:set_options_fun -> "
- "set-option ipfamily to inet6fb4"),
- Res = httpc:set_options([{ipfamily, inet6fb4}]),
- tsp("init_per_testcase:set_options_fun -> "
- "~n Res: ~p", [Res]),
- Res
- end),
+ %% No need? Since it is set above?
+
+ %% tsp("init_per_testcase -> allways try IPv6 on windows"),
+ %% ?RUN_ON_WINDOWS(
+ %% fun() ->
+ %% tsp("init_per_testcase:set_options_fun -> "
+ %% "set-option ipfamily to inet6fb4"),
+ %% Res = httpc:set_options([{ipfamily, inet6fb4}]),
+ %% tsp("init_per_testcase:set_options_fun -> "
+ %% "~n Res: ~p", [Res]),
+ %% Res
+ %% end),
TmpConfig2 = lists:keydelete(local_server, 1, TmpConfig),
%% Will start inets
@@ -441,6 +457,7 @@ end_per_testcase(http_save_to_file = Case, Config) ->
end_per_testcase(Case, Config) ->
io:format(user, "~n~n*** END ~w:~w ***~n~n",
[?MODULE, Case]),
+ dbg:stop(), % ?
case atom_to_list(Case) of
"ipv6_" ++ _Rest ->
tsp("end_per_testcase(~w) -> stop ssl", [Case]),
@@ -1267,8 +1284,8 @@ http_redirect(Config) when is_list(Config) ->
"~n Config: ~p", [Config]),
case ?config(local_server, Config) of
ok ->
- tsp("http_redirect -> set ipfamily option to inet"),
- ok = httpc:set_options([{ipfamily, inet}]),
+ %% tsp("http_redirect -> set ipfamily option to inet"),
+ %% ok = httpc:set_options([{ipfamily, inet}]),
tsp("http_redirect -> start dummy server inet"),
{DummyServerPid, Port} = dummy_server(ipv4),
@@ -3316,7 +3333,8 @@ create_config(FileName, ComType, Port, PrivDir, ServerRoot, DocRoot,
" mod_include mod_dir mod_get mod_head"
" mod_log mod_disk_log mod_trace",
- BindAddress = "*|inet",
+ %% BindAddress = "*|inet", % Force the use of IPv4
+ BindAddress = "*", % This corresponds to using IpFamily inet6fb4
HttpConfig = [
cline(["BindAddress ", BindAddress]),
diff --git a/lib/inets/test/httpd_SUITE.erl b/lib/inets/test/httpd_SUITE.erl
index 07c529acc8..41e4188e5f 100644
--- a/lib/inets/test/httpd_SUITE.erl
+++ b/lib/inets/test/httpd_SUITE.erl
@@ -2357,29 +2357,30 @@ create_config(Config, Access, FileName) ->
true ->
[]
end,
- ModOrder = case Access of
- mod_htaccess ->
- "Modules mod_alias mod_htaccess mod_auth "
- "mod_security "
- "mod_responsecontrol mod_trace mod_esi "
- "mod_actions mod_cgi mod_include mod_dir "
- "mod_range mod_get "
- "mod_head mod_log mod_disk_log";
- _ ->
- "Modules mod_alias mod_auth mod_security "
- "mod_responsecontrol mod_trace mod_esi "
- "mod_actions mod_cgi mod_include mod_dir "
+ ModOrder =
+ case Access of
+ mod_htaccess ->
+ "Modules mod_alias mod_htaccess mod_auth "
+ "mod_security "
+ "mod_responsecontrol mod_trace mod_esi "
+ "mod_actions mod_cgi mod_include mod_dir "
+ "mod_range mod_get "
+ "mod_head mod_log mod_disk_log";
+ _ ->
+ "Modules mod_alias mod_auth mod_security "
+ "mod_responsecontrol mod_trace mod_esi "
+ "mod_actions mod_cgi mod_include mod_dir "
"mod_range mod_get "
- "mod_head mod_log mod_disk_log"
- end,
+ "mod_head mod_log mod_disk_log"
+ end,
-%% The test suite currently does not handle an explicit BindAddress.
-%% They assume any has been used, that is Addr is always set to undefined!
+ %% The test suite currently does not handle an explicit BindAddress.
+ %% They assume any has been used, that is Addr is always set to undefined!
-%% {ok, Hostname} = inet:gethostname(),
-%% {ok, Addr} = inet:getaddr(Hostname, inet6),
-%% AddrStr = make_ipv6(Addr),
-%% BindAddress = lists:flatten(io_lib:format("~s|inet6", [AddrStr])),
+ %% {ok, Hostname} = inet:gethostname(),
+ %% {ok, Addr} = inet:getaddr(Hostname, inet6),
+ %% AddrStr = make_ipv6(Addr),
+ %% BindAddress = lists:flatten(io_lib:format("~s|inet6", [AddrStr])),
BindAddress = "*|inet",
%% BindAddress = "*",
diff --git a/lib/inets/test/inets_test_lib.erl b/lib/inets/test/inets_test_lib.erl
index a4815becba..c94be796cd 100644
--- a/lib/inets/test/inets_test_lib.erl
+++ b/lib/inets/test/inets_test_lib.erl
@@ -494,83 +494,78 @@ connect_byte(ip_comm, Host, Port, Opts0) ->
connect(ip_comm, Host, Port, Opts).
-connect(ssl, Host, Port, Opts) ->
+%% This always falls back on IPV4, but tries IPV6 first.
+connect(Proto, Host, Port, Opts0) ->
+ Opts = Opts0 -- [inet, inet6],
+ connect(Proto, Host, Port, Opts ++ [inet6], inet6).
+
+connect(ssl, Host, Port, Opts, Type) ->
tsp("connect(ssl) -> entry with"
"~n Host: ~p"
"~n Port: ~p"
- "~n Opts: ~p", [Host, Port, Opts]),
+ "~n Opts: ~p"
+ "~n Type: ~p", [Host, Port, Opts, Type]),
ssl:start(),
%% We ignore this option for ssl...
%% ...maybe we should really treat this in the same way as ip_comm...
- case ssl:connect(Host, Port, lists:delete(inet6fb4, Opts)) of
+ case ssl:connect(Host, Port, Opts) of
{ok, Socket} ->
{ok, Socket};
+ {error, Reason} when Type =:= inet6 ->
+ tsp("connect(ssl) -> failed connecting with inet6: "
+ "~n Reason: ~p"
+ "~n trying inet", [Reason]),
+ connect(ssl, Host, Port, Opts -- [inet6], inet);
{error, Reason} ->
- {error, Reason};
+ tsp("connect(ssl) -> failed connecting: "
+ "~n Reason: ~p", [Reason]),
+ {error, Reason};
Error ->
Error
end;
-connect(ip_comm, Host, Port, Opts) ->
+connect(ip_comm, Host, Port, Opts, Type) ->
tsp("connect(ip_comm) -> entry with"
"~n Host: ~p"
"~n Port: ~p"
- "~n Opts: ~p", [Host, Port, Opts]),
+ "~n Opts: ~p"
+ "~n Type: ~p", [Host, Port, Opts, Type]),
- %% We check for precence of inet6fb4.
- %% If found, we shall try inet6 and if that does not work
- %% try inet (regardless of error reason)
- case lists:delete(inet6fb4, Opts) of
- Opts ->
- %% Nope, run as usual, where we use error reason
- %% to detect if we are on IPv6 or not...
- case gen_tcp:connect(Host,Port, Opts) of
- {ok, Socket} ->
- tsp("connect success"),
- {ok, Socket};
- {error, nxdomain} ->
- tsp("connect error nxdomain when opts: ~p", [Opts]),
- connect(ip_comm, Host, Port, lists:delete(inet6, Opts));
- {error, eafnosupport} ->
- tsp("connect error eafnosupport when opts: ~p", [Opts]),
- connect(ip_comm, Host, Port, lists:delete(inet6, Opts));
- {error, econnreset} ->
- tsp("connect error econnreset when opts: ~p", [Opts]),
- connect(ip_comm, Host, Port, lists:delete(inet6, Opts));
- {error, enetunreach} ->
- tsp("connect error eafnosupport when opts: ~p", [Opts]),
- connect(ip_comm, Host, Port, lists:delete(inet6, Opts));
- {error, {enfile,_}} ->
- tsp("connect error enfile when opts: ~p", [Opts]),
- {error, enfile};
- Error ->
- tsp("connect(ip_conn) -> Unexpected error: "
- "~n Error: ~p"
- "~nwhen"
- "~n Host: ~p"
- "~n Port: ~p"
- "~n Opts: ~p"
- "~n", [Error, Host, Port, Opts]),
- Error
- end;
+ case gen_tcp:connect(Host, Port, Opts) of
+ {ok, Socket} ->
+ tsp("connect success"),
+ {ok, Socket};
- Opts2 ->
- %% Yep, so try first with inet6 and if that fails inet
- case gen_tcp:connect(Host, Port, [inet6|Opts2]) of
- {ok, Socket} ->
- tsp("connect success"),
- {ok, Socket};
- {error, Reason_inet6} ->
- tsp("inet6 connect failed: ~p", [Reason_inet6]),
- case gen_tcp:connect(Host, Port, [inet|Opts2]) of
- {ok, Socket} ->
- tsp("connect success"),
- {ok, Socket};
- {error, Reason_inet} ->
- tsp("inet connect also failed: ~p", [Reason_inet]),
- {error, {connect_failure, [{inet6, Reason_inet6},
- {inet, Reason_inet}]}}
- end
- end
+ {error, nxdomain} when Type =:= inet6 ->
+ tsp("connect error nxdomain when"
+ "~n Opts: ~p", [Opts]),
+ connect(ip_comm, Host, Port, Opts -- [inet6], inet);
+ {error, eafnosupport} when Type =:= inet6 ->
+ tsp("connect error eafnosupport when"
+ "~n Opts: ~p", [Opts]),
+ connect(ip_comm, Host, Port, Opts -- [inet6], inet);
+ {error, econnreset} when Type =:= inet6 ->
+ tsp("connect error econnreset when"
+ "~n Opts: ~p", [Opts]),
+ connect(ip_comm, Host, Port, Opts -- [inet6], inet);
+ {error, enetunreach} when Type =:= inet6 ->
+ tsp("connect error eafnosupport when"
+ "~n Opts: ~p", [Opts]),
+ connect(ip_comm, Host, Port, Opts -- [inet6], inet);
+ {error, econnrefused} when Type =:= inet6 ->
+ tsp("connect error econnrefused when"
+ "~n Opts: ~p", [Opts]),
+ connect(ip_comm, Host, Port, Opts -- [inet6], inet);
+
+ Error ->
+ tsp("connect(ip_conn) -> Fatal connect error: "
+ "~n Error: ~p"
+ "~nwhen"
+ "~n Host: ~p"
+ "~n Port: ~p"
+ "~n Opts: ~p"
+ "~n Type: ~p"
+ "~n", [Error, Host, Port, Opts, Type]),
+ Error
end.