8146758: NetworkInterfaceStreamTest.java fails intermittently at comparing network interfaces

Reviewed-by: chegar
This commit is contained in:
Felix Yang 2016-04-19 01:40:13 -07:00 committed by Felix Yang
parent 6f26ab8d12
commit 2ea14c96f7

View File

@ -28,7 +28,6 @@
* @build java.base/java.util.stream.OpTestCase
* @run testng/othervm NetworkInterfaceStreamTest
* @run testng/othervm -Djava.net.preferIPv4Stack=true NetworkInterfaceStreamTest
* @key intermittent
*/
import org.testng.annotations.Test;
@ -52,21 +51,26 @@ public class NetworkInterfaceStreamTest extends OpTestCase {
public void testNetworkInterfaces() throws SocketException {
Supplier<Stream<NetworkInterface>> ss = () -> {
try {
return NetworkInterface.networkInterfaces();
return allNetworkInterfaces();
}
catch (SocketException e) {
throw new RuntimeException(e);
}
};
Collection<NetworkInterface> expected = Collections.list(NetworkInterface.getNetworkInterfaces());
Collection<NetworkInterface> enums = Collections.list(NetworkInterface.getNetworkInterfaces());
Collection<NetworkInterface> expected = new ArrayList<>();
enums.forEach(ni -> {
if (isIncluded(ni)) {
expected.add(ni);
}
});
withData(TestData.Factory.ofSupplier("Top-level network interfaces", ss))
.stream(s -> s)
.expectedResult(expected)
.exercise();
}
private Collection<NetworkInterface> getAllNetworkInterfaces() throws SocketException {
Collection<NetworkInterface> anis = new ArrayList<>();
for (NetworkInterface ni : Collections.list(NetworkInterface.getNetworkInterfaces())) {