|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
50 | 50 | public class JdwpAttachTest {
|
51 | 51 |
|
52 | 52 | // Set to true to perform testing of attach from wrong address (expected to fail).
|
53 |
| - // It's off by default as it caused significant test time increase\ |
| 53 | + // It's off by default as it caused significant test time increase |
54 | 54 | // (tests <number_of_addresses> * <number_of_addresses> cases, each case fails by timeout).
|
55 | 55 | private static boolean testFailedAttach = false;
|
56 | 56 |
|
| 57 | + // A flag to exclude testcases which can cause intermittent CI failures. |
| 58 | + private static boolean testPotentiallyUnstableCases = false; |
| 59 | + |
57 | 60 | public static void main(String[] args) throws Exception {
|
58 | 61 | List<InetAddress> addresses = Utils.getAddressesWithSymbolicAndNumericScopes();
|
59 | 62 |
|
@@ -81,11 +84,15 @@ public static void main(String[] args) throws Exception {
|
81 | 84 | }
|
82 | 85 | }
|
83 | 86 |
|
84 |
| - // by using "localhost" or empty hostname |
85 |
| - // we should be able to attach to both IPv4 and IPv6 addresses (127.0.0.1 & ::1) |
| 87 | + // By using "localhost" or empty hostname we should be able to attach |
| 88 | + // to both IPv4 and IPv6 addresses (127.0.0.1 & ::1). |
| 89 | + // By default test verifies only "preferred" family (IPv4 or IPv6). |
| 90 | + // Need to set testPotentiallyUnstableCases to true to perform full testing. |
86 | 91 | InetAddress localAddresses[] = InetAddress.getAllByName("localhost");
|
87 | 92 | for (int i = 0; i < localAddresses.length; i++) {
|
88 |
| - attachTest(localAddresses[i].getHostAddress(), "", true); |
| 93 | + if (testPotentiallyUnstableCases || addressIsSafeToConnectToLocalhost(localAddresses[i])) { |
| 94 | + attachTest(localAddresses[i].getHostAddress(), "", true); |
| 95 | + } |
89 | 96 | }
|
90 | 97 | }
|
91 | 98 |
|
@@ -168,6 +175,15 @@ private static void setConnectorArg(Map<String, Connector.Argument> args, String
|
168 | 175 | arg.setValue(value);
|
169 | 176 | }
|
170 | 177 |
|
| 178 | + // Attach to localhost tries to connect to both IPv4 and IPv6 loopback addresses. |
| 179 | + // But sometimes it causes interference with other processes which can listen |
| 180 | + // on the same port but different loopback address. |
| 181 | + // The method checks if the address is safe to test with current network config. |
| 182 | + private static boolean addressIsSafeToConnectToLocalhost(InetAddress addr) { |
| 183 | + boolean ipv6 = Boolean.parseBoolean(System.getProperty("java.net.preferIPv6Addresses")); |
| 184 | + return ipv6 == (addr instanceof Inet6Address); |
| 185 | + } |
| 186 | + |
171 | 187 | private static long startTime = System.currentTimeMillis();
|
172 | 188 |
|
173 | 189 | private static void log(Object o) {
|
|
0 commit comments