diff options
author | Loïc Hoguin <[email protected]> | 2020-03-26 09:57:10 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2020-03-26 09:57:10 +0100 |
commit | a7e069e6ff2729d774c712e3ddd01d3348202db6 (patch) | |
tree | ab1a67d72df6214708723f7f6128b0eeb5b298a1 /test/gun_test.erl | |
parent | d1d02a0ebc1a5d9852b7fe5216ac4ce628fb1744 (diff) | |
download | gun-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.
Diffstat (limited to 'test/gun_test.erl')
-rw-r--r-- | test/gun_test.erl | 10 |
1 files changed, 7 insertions, 3 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), |