From c97216ecdd9e684f6f6e3bfee8fae8e2e8933f13 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Mon, 16 Oct 2017 15:26:44 +0200 Subject: jinterface: Skip tests when hostname cannot be resolved Check that the hostname can be resolved by the native resolver. What normally has happened when it cannot is that gethostname() returned a fqdn and `hostname -s` is not part of /etc/hosts. This is solved on the erlang side by adding `hostname -s` to inet_db, but java does not have a similar mechanism, so it fails when it tries to connect to `hostname -s`. This caused jinterface tests to fail when run in such an environment, and travis-ci recently started doing this. --- lib/jinterface/test/jinterface_SUITE.erl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/jinterface/test/jinterface_SUITE.erl b/lib/jinterface/test/jinterface_SUITE.erl index 73851f47e0..8c6a6368a9 100644 --- a/lib/jinterface/test/jinterface_SUITE.erl +++ b/lib/jinterface/test/jinterface_SUITE.erl @@ -176,11 +176,29 @@ init_per_suite(Config) when is_list(Config) -> {error,bad_name} -> false; P -> filelib:is_dir(P) end of true -> - jitu:init_all(Config); + case hostname_resolves() of + true -> + jitu:init_all(Config); + Skip -> + Skip + end; false -> {skip,"No jinterface application"} end. +%% Check if inet:gethostname() can be resolved by +%% the native resolver. If it can, we know that +%% jinterface name resolution works. If it cannot +%% jinterface tests will fail. +hostname_resolves() -> + {ok, HN} = inet:gethostname(), + case inet_gethost_native:gethostbyname(HN) of + {ok, _} -> + true; + _ -> + {skip, "Cannot resolve short hostname, add " ++ HN ++ " to /etc/hosts"} + end. + end_per_suite(Config) when is_list(Config) -> jitu:finish_all(Config). -- cgit v1.2.3