8268714: [macos-aarch64] 7 java/net/httpclient/websocket tests failed

Reviewed-by: chegar, michaelm
This commit is contained in:
Daniel Fuchs 2021-06-16 17:24:06 +00:00
parent 38dbe05e00
commit 8ea0606aba
12 changed files with 93 additions and 7 deletions

View File

@ -278,6 +278,7 @@ public class ISO_8859_1_Test implements HttpServerAdapters {
@Test(dataProvider = "variants")
public void test(String uri, boolean sameClient) throws Exception {
checkSkip();
System.out.println("Request to " + uri);
HttpClient client = newHttpClient(sameClient);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -150,7 +150,7 @@ public class DummyWebSocketServer implements Closeable {
err.println("Error in connection: " + channel + ", " + e);
} finally {
err.println("Closed: " + channel);
close(channel);
closeChannel(channel);
readReady.countDown();
}
}
@ -184,6 +184,10 @@ public class DummyWebSocketServer implements Closeable {
}
}
protected void closeChannel(SocketChannel channel) {
close(channel);
}
protected void write(SocketChannel ch) throws IOException { }
protected final void serve(SocketChannel channel)

View File

@ -25,6 +25,7 @@
* @test
* @build DummyWebSocketServer
* @run testng/othervm
* -Djdk.httpclient.sendBufferSize=8192
* -Djdk.internal.httpclient.debug=true
* -Djdk.internal.httpclient.websocket.debug=true
* PendingBinaryPingClose
@ -48,6 +49,7 @@ public class PendingBinaryPingClose extends PendingOperations {
public void pendingBinaryPingClose(boolean last) throws Exception {
repeatable(() -> {
server = Support.notReadingServer();
server.setReceiveBufferSize(1024);
server.open();
webSocket = httpClient().newWebSocketBuilder()
.buildAsync(server.getURI(), new WebSocket.Listener() { })

View File

@ -25,6 +25,7 @@
* @test
* @build DummyWebSocketServer
* @run testng/othervm
* -Djdk.httpclient.sendBufferSize=8192
* -Djdk.internal.httpclient.debug=true
* -Djdk.internal.httpclient.websocket.debug=true
* PendingBinaryPongClose
@ -50,6 +51,7 @@ public class PendingBinaryPongClose extends PendingOperations {
public void pendingBinaryPongClose(boolean last) throws Exception {
repeatable(() -> {
server = Support.notReadingServer();
server.setReceiveBufferSize(1024);
server.open();
webSocket = httpClient().newWebSocketBuilder()
.buildAsync(server.getURI(), new WebSocket.Listener() { })

View File

@ -25,6 +25,7 @@
* @test
* @build DummyWebSocketServer
* @run testng/othervm
* -Djdk.httpclient.sendBufferSize=8192
* PendingPingBinaryClose
*/
@ -50,6 +51,7 @@ public class PendingPingBinaryClose extends PendingOperations {
public void pendingPingBinaryClose(boolean last) throws Exception {
repeatable( () -> {
server = Support.notReadingServer();
server.setReceiveBufferSize(1024);
server.open();
webSocket = httpClient().newWebSocketBuilder()
.buildAsync(server.getURI(), new WebSocket.Listener() { })

View File

@ -25,6 +25,7 @@
* @test
* @build DummyWebSocketServer
* @run testng/othervm
* -Djdk.httpclient.sendBufferSize=8192
* PendingPingTextClose
*/
@ -52,6 +53,7 @@ public class PendingPingTextClose extends PendingOperations {
try {
repeatable(() -> {
server = Support.notReadingServer();
server.setReceiveBufferSize(1024);
server.open();
webSocket = httpClient().newWebSocketBuilder()
.buildAsync(server.getURI(), new WebSocket.Listener() { })

View File

@ -25,6 +25,7 @@
* @test
* @build DummyWebSocketServer
* @run testng/othervm
* -Djdk.httpclient.sendBufferSize=8192
* PendingPongBinaryClose
*/
@ -50,6 +51,7 @@ public class PendingPongBinaryClose extends PendingOperations {
public void pendingPongBinaryClose(boolean last) throws Exception {
repeatable( () -> {
server = Support.notReadingServer();
server.setReceiveBufferSize(1024);
server.open();
webSocket = httpClient().newWebSocketBuilder()
.buildAsync(server.getURI(), new WebSocket.Listener() { })

View File

@ -25,6 +25,7 @@
* @test
* @build DummyWebSocketServer
* @run testng/othervm
* -Djdk.httpclient.sendBufferSize=8192
* PendingPongTextClose
*/
@ -50,6 +51,7 @@ public class PendingPongTextClose extends PendingOperations {
public void pendingPongTextClose(boolean last) throws Exception {
repeatable( () -> {
server = Support.notReadingServer();
server.setReceiveBufferSize(1024);
server.open();
webSocket = httpClient().newWebSocketBuilder()
.buildAsync(server.getURI(), new WebSocket.Listener() { })

View File

@ -27,6 +27,7 @@
* @run testng/othervm
* -Djdk.internal.httpclient.debug=true
* -Djdk.internal.httpclient.websocket.debug=true
* -Djdk.httpclient.sendBufferSize=8192
* PendingTextPongClose
*/
@ -49,6 +50,7 @@ public class PendingTextPongClose extends PendingOperations {
public void pendingTextPongClose(boolean last) throws Exception {
repeatable(() -> {
server = Support.notReadingServer();
server.setReceiveBufferSize(1024);
server.open();
webSocket = httpClient().newWebSocketBuilder()
.buildAsync(server.getURI(), new WebSocket.Listener() { })

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -136,17 +136,65 @@ public class Support {
*/
public static DummyWebSocketServer notReadingServer() {
return new DummyWebSocketServer() {
volatile Thread reader;
@Override
protected void read(SocketChannel ch) throws IOException {
reader = Thread.currentThread();
try {
System.out.println("Not reading server waiting");
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
@Override
protected void closeChannel(SocketChannel channel) {
try {
long read = drain(channel);
System.out.printf("Not reading server drained %s bytes%n", read);
} catch (IOException io) {
System.out.println("Not reading server failed to drain channel: " + io);
}
super.closeChannel(channel);
}
@Override
public void close() {
super.close();
Thread thread = reader;
if (thread != null && thread.isAlive() && thread != Thread.currentThread()) {
try {
thread.join();
System.out.println("Not reading server: closed");
} catch (InterruptedException x) {
System.out.println("Not reading server: close interrupted: " + x);
}
}
}
};
}
static long drain(SocketChannel channel) throws IOException {
System.out.println("Not reading server: draining socket");
var blocking = channel.isBlocking();
if (blocking) channel.configureBlocking(false);
long count = 0;
try {
ByteBuffer buffer = ByteBuffer.allocateDirect(8 * 1024);
int read;
while ((read = channel.read(buffer)) > 0) {
count += read;
buffer.clear();
}
return count;
} finally {
if (blocking != channel.isBlocking()) {
channel.configureBlocking(blocking);
}
}
}
public static DummyWebSocketServer writingServer(int... data) {
byte[] copy = new byte[data.length];
for (int i = 0; i < data.length; i++) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -76,8 +76,9 @@ public class WSHandshakeExceptionTest {
String httpsURI;
String httpNonUtf8URI;
String httpsNonUtf8URI;
HttpClient sharedClient;
static final int ITERATION_COUNT = 10;
static final int ITERATION_COUNT = 4;
// a shared executor helps reduce the amount of threads created by the test
static final ExecutorService executor = Executors.newCachedThreadPool();
@ -106,11 +107,16 @@ public class WSHandshakeExceptionTest {
@Test(dataProvider = "variants")
public void test(String uri, boolean sameClient) {
HttpClient client = null;
HttpClient client = sharedClient;
boolean pause;
for (int i = 0; i < ITERATION_COUNT; i++) {
System.out.printf("iteration %s%n", i);
if (!sameClient || client == null)
if (!sameClient || client == null) {
pause = client != null;
client = newHttpClient();
if (pause) gc(10); // give some time to gc
}
if (sharedClient == null) sharedClient = client;
try {
client.newWebSocketBuilder()
@ -143,6 +149,15 @@ public class WSHandshakeExceptionTest {
}
}
static void gc(long ms) {
System.gc();
try {
Thread.sleep(ms);
} catch (InterruptedException x) {
// OK
}
}
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
@ -168,6 +183,8 @@ public class WSHandshakeExceptionTest {
@AfterTest
public void teardown() {
sharedClient = null;
gc(100);
httpTestServer.stop(0);
httpsTestServer.stop(0);
executor.shutdownNow();

View File

@ -404,6 +404,8 @@ public class WebSocketProxyTest {
@BeforeMethod
public void breakBetweenTests() {
System.gc();
try {Thread.sleep(100); } catch (InterruptedException x) { /* OK */ }
System.out.println("\n-------\n");
}
}