aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2020-03-26 09:57:10 +0100
committerLoïc Hoguin <[email protected]>2020-03-26 09:57:10 +0100
commita7e069e6ff2729d774c712e3ddd01d3348202db6 (patch)
treeab1a67d72df6214708723f7f6128b0eeb5b298a1
parentd1d02a0ebc1a5d9852b7fe5216ac4ce628fb1744 (diff)
downloadgun-a7e069e6ff2729d774c712e3ddd01d3348202db6.tar.gz
gun-a7e069e6ff2729d774c712e3ddd01d3348202db6.tar.bz2
gun-a7e069e6ff2729d774c712e3ddd01d3348202db6.zip
Fix IPv6 related changes to tests
Turns out we can't rely on IPv4 being available if we set the socket in IPv6 mode. Instead the origin is modified to either setup IPv4 or IPv6 depending on the test's needs.
-rw-r--r--test/gun_test.erl10
-rw-r--r--test/rfc7230_SUITE.erl2
-rw-r--r--test/rfc7540_SUITE.erl2
3 files changed, 9 insertions, 5 deletions
diff --git a/test/gun_test.erl b/test/gun_test.erl
index c6cdd8c..84f0a88 100644
--- a/test/gun_test.erl
+++ b/test/gun_test.erl
@@ -44,9 +44,13 @@ init_origin(Transport, Protocol, Fun) ->
Port = receive_from(Pid),
{ok, Pid, Port}.
-init_origin(Parent, tcp, Protocol, Fun) ->
- %% We setup the socket for both IPv4 and IPv6.
- {ok, ListenSocket} = gen_tcp:listen(0, [binary, {active, false}, inet6]),
+init_origin(Parent, Transport, Protocol, Fun)
+ when Transport =:= tcp; Transport =:= tcp6 ->
+ InetOpt = case Transport of
+ tcp -> inet;
+ tcp6 -> inet6
+ end,
+ {ok, ListenSocket} = gen_tcp:listen(0, [binary, {active, false}, InetOpt]),
{ok, {_, Port}} = inet:sockname(ListenSocket),
Parent ! {self(), Port},
{ok, ClientSocket} = gen_tcp:accept(ListenSocket, 5000),
diff --git a/test/rfc7230_SUITE.erl b/test/rfc7230_SUITE.erl
index d6afb2c..8505d3f 100644
--- a/test/rfc7230_SUITE.erl
+++ b/test/rfc7230_SUITE.erl
@@ -37,7 +37,7 @@ host_default_port_https(_) ->
host_ipv6(_) ->
doc("When connecting to a server using an IPv6 address the host "
"header must wrap the address with brackets. (RFC7230 5.4, RFC3986 3.2.2)"),
- {ok, OriginPid, OriginPort} = init_origin(tcp, http),
+ {ok, OriginPid, OriginPort} = init_origin(tcp6, http),
{ok, ConnPid} = gun:open({0,0,0,0,0,0,0,1}, OriginPort, #{transport => tcp}),
{ok, http} = gun:await_up(ConnPid),
_ = gun:get(ConnPid, "/"),
diff --git a/test/rfc7540_SUITE.erl b/test/rfc7540_SUITE.erl
index 56447a3..37e6903 100644
--- a/test/rfc7540_SUITE.erl
+++ b/test/rfc7540_SUITE.erl
@@ -38,7 +38,7 @@ authority_default_port_https(_) ->
authority_ipv6(_) ->
doc("When connecting to a server using an IPv6 address the :authority "
"pseudo-header must wrap the address with brackets. (RFC7540 8.1.2.3, RFC3986 3.2.2)"),
- {ok, OriginPid, OriginPort} = init_origin(tcp, http2, fun(Parent, Socket, Transport) ->
+ {ok, OriginPid, OriginPort} = init_origin(tcp6, http2, fun(Parent, Socket, Transport) ->
%% Receive the HEADERS frame and send the headers decoded.
{ok, <<Len:24, 1:8, _:8, 1:32>>} = Transport:recv(Socket, 9, 1000),
{ok, ReqHeadersBlock} = Transport:recv(Socket, Len, 1000),