[mercedesme] Fix unstable ConfigurationTest (#13650)

* Make sure IPv4 is used with default callback URL
* Use a more reasonable timeout

Fixes #13531

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2022-11-03 22:16:07 +01:00 committed by GitHub
parent 54ccf847da
commit a4f6159f09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -12,6 +12,7 @@
*/
package org.openhab.binding.mercedesme.internal.server;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
@ -70,7 +71,9 @@ public class Utils {
for (Enumeration<InetAddress> addresses = iface.getInetAddresses(); addresses
.hasMoreElements();) {
InetAddress address = addresses.nextElement();
return address.getHostAddress();
if (address instanceof Inet4Address) {
return address.getHostAddress();
}
}
}
}

View File

@ -62,10 +62,11 @@ class ConfigurationTest {
@Test
public void testCallbackUrl() throws SocketException {
String ip = Utils.getCallbackIP();
String message = "IP " + ip + " not reachable";
try {
assertTrue(InetAddress.getByName(ip).isReachable(10));
assertTrue(InetAddress.getByName(ip).isReachable(10000), message);
} catch (IOException e) {
assertTrue(false, "IP " + ip + " not reachable");
fail(message);
}
}
}