diff options
author | Micael Karlberg <[email protected]> | 2019-05-20 12:11:24 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2019-05-29 13:47:40 +0200 |
commit | da690a3c9857413943ab8534e27ab9a2ff54a4cb (patch) | |
tree | e3d11b53245a6a55b21d7cb40ed236111e70be2b /erts/emulator/test/socket_SUITE.erl | |
parent | fa4c61fe7eb34e6fdb2b1c77e6252a76577cb465 (diff) | |
download | otp-da690a3c9857413943ab8534e27ab9a2ff54a4cb.tar.gz otp-da690a3c9857413943ab8534e27ab9a2ff54a4cb.tar.bz2 otp-da690a3c9857413943ab8534e27ab9a2ff54a4cb.zip |
[esock|test] Try even harder to make unique path
Some (Unix Domain socket) test cases fails because the
path (supposedly) already existed on a (admittedly old) gento VM.
So, we try enen harder to ensure that the path is unique...
OTP-15822
Diffstat (limited to 'erts/emulator/test/socket_SUITE.erl')
-rw-r--r-- | erts/emulator/test/socket_SUITE.erl | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/erts/emulator/test/socket_SUITE.erl b/erts/emulator/test/socket_SUITE.erl index bc359ddf70..0970739a19 100644 --- a/erts/emulator/test/socket_SUITE.erl +++ b/erts/emulator/test/socket_SUITE.erl @@ -1951,8 +1951,14 @@ api_b_send_and_recv_udp(InitState) -> end}, #{desc => "bind src", cmd => fun(#{sock_src := Sock, lsa_src := LSA}) -> - sock_bind(Sock, LSA), - ok + case socket:bind(Sock, LSA) of + {ok, _Port} -> + ?SEV_IPRINT("src bound"), + ok; + {error, Reason} = ERROR -> + ?SEV_EPRINT("src bind failed: ~p", [Reason]), + ERROR + end end}, #{desc => "sockname src socket", cmd => fun(#{sock_src := Sock} = State) -> @@ -1970,8 +1976,14 @@ api_b_send_and_recv_udp(InitState) -> end}, #{desc => "bind dst", cmd => fun(#{sock_dst := Sock, lsa_dst := LSA}) -> - sock_bind(Sock, LSA), - ok + case socket:bind(Sock, LSA) of + {ok, _Port} -> + ?SEV_IPRINT("src bound"), + ok; + {error, Reason} = ERROR -> + ?SEV_EPRINT("src bind failed: ~p", [Reason]), + ERROR + end end}, #{desc => "sockname dst socket", cmd => fun(#{sock_dst := Sock} = State) -> @@ -6593,8 +6605,14 @@ sc_lc_receive_response_udp(InitState) -> end}, #{desc => "bind socket", cmd => fun(#{sock := Sock, local_sa := LSA}) -> - sock_bind(Sock, LSA), - ok + case socket:bind(Sock, LSA) of + {ok, _Port} -> + ?SEV_IPRINT("src bound"), + ok; + {error, Reason} = ERROR -> + ?SEV_EPRINT("src bind failed: ~p", [Reason]), + ERROR + end end}, #{desc => "announce ready (init)", cmd => fun(#{tester := Tester, sock := Sock}) -> @@ -19899,8 +19917,27 @@ local_host() -> %% don't clash. mk_unique_path() -> [NodeName | _] = string:tokens(atom_to_list(node()), [$@]), - ?LIB:f("/tmp/esock_~s_~w", [NodeName, erlang:system_time(nanosecond)]). + Path = ?LIB:f("/tmp/esock_~s_~w", [NodeName, erlang:system_time(nanosecond)]), + ensure_unique_path(Path). + +ensure_unique_path(Path) -> + case file:read_file_info(Path) of + {ok, _} -> % Ouch, append a unique ID and try again + ensure_unique_path(Path, 1); + {error, _} -> % We assume this means it does not exist yet... + Path + end. +ensure_unique_path(Path, ID) -> + NewPath = ?LIB:f("~s_~w", [Path, ID]), + case file:read_file_info(NewPath) of + {ok, _} -> % Ouch, this also existed, increment and try again + ensure_unique_path(Path, ID + 1); + {error, _} -> % We assume this means it does not exist yet... + NewPath + end. + + which_local_socket_addr(local = Domain) -> #{family => Domain, path => mk_unique_path()}; |