Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
8268714: [macos-aarch64] 7 java/net/httpclient/websocket tests failed
Reviewed-by: chegar, michaelm
  • Loading branch information
dfuch committed Jun 16, 2021
1 parent 38dbe05 commit 8ea0606
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 7 deletions.
1 change: 1 addition & 0 deletions test/jdk/java/net/httpclient/ISO_8859_1_Test.java
Expand Up @@ -278,6 +278,7 @@ private static final Exception completionCause(CompletionException x) {

@Test(dataProvider = "variants")
public void test(String uri, boolean sameClient) throws Exception {
checkSkip();
System.out.println("Request to " + uri);

HttpClient client = newHttpClient(sameClient);
Expand Down
@@ -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
Expand Down Expand Up @@ -150,7 +150,7 @@ public DummyWebSocketServer(BiFunction<List<String>,Credentials,List<String>> ma
err.println("Error in connection: " + channel + ", " + e);
} finally {
err.println("Closed: " + channel);
close(channel);
closeChannel(channel);
readReady.countDown();
}
}
Expand Down Expand Up @@ -184,6 +184,10 @@ protected void read(SocketChannel ch) throws IOException {
}
}

protected void closeChannel(SocketChannel channel) {
close(channel);
}

protected void write(SocketChannel ch) throws IOException { }

protected final void serve(SocketChannel channel)
Expand Down
Expand Up @@ -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
Expand All @@ -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() { })
Expand Down
Expand Up @@ -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
Expand All @@ -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() { })
Expand Down
Expand Up @@ -25,6 +25,7 @@
* @test
* @build DummyWebSocketServer
* @run testng/othervm
* -Djdk.httpclient.sendBufferSize=8192
* PendingPingBinaryClose
*/

Expand All @@ -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() { })
Expand Down
Expand Up @@ -25,6 +25,7 @@
* @test
* @build DummyWebSocketServer
* @run testng/othervm
* -Djdk.httpclient.sendBufferSize=8192
* PendingPingTextClose
*/

Expand Down Expand Up @@ -52,6 +53,7 @@ public void pendingPingTextClose(boolean last) throws Exception {
try {
repeatable(() -> {
server = Support.notReadingServer();
server.setReceiveBufferSize(1024);
server.open();
webSocket = httpClient().newWebSocketBuilder()
.buildAsync(server.getURI(), new WebSocket.Listener() { })
Expand Down
Expand Up @@ -25,6 +25,7 @@
* @test
* @build DummyWebSocketServer
* @run testng/othervm
* -Djdk.httpclient.sendBufferSize=8192
* PendingPongBinaryClose
*/

Expand All @@ -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() { })
Expand Down
Expand Up @@ -25,6 +25,7 @@
* @test
* @build DummyWebSocketServer
* @run testng/othervm
* -Djdk.httpclient.sendBufferSize=8192
* PendingPongTextClose
*/

Expand All @@ -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() { })
Expand Down
Expand Up @@ -27,6 +27,7 @@
* @run testng/othervm
* -Djdk.internal.httpclient.debug=true
* -Djdk.internal.httpclient.websocket.debug=true
* -Djdk.httpclient.sendBufferSize=8192
* PendingTextPongClose
*/

Expand All @@ -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() { })
Expand Down
50 changes: 49 additions & 1 deletion test/jdk/java/net/httpclient/websocket/Support.java
@@ -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
Expand Down Expand Up @@ -136,17 +136,65 @@ protected void write(SocketChannel ch) throws IOException {
*/
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++) {
Expand Down
@@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -106,11 +107,16 @@ HttpClient newHttpClient() {

@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()
Expand Down Expand Up @@ -143,6 +149,15 @@ public void test(String uri, boolean sameClient) {
}
}

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();
Expand All @@ -168,6 +183,8 @@ public void setup() throws Exception {

@AfterTest
public void teardown() {
sharedClient = null;
gc(100);
httpTestServer.stop(0);
httpsTestServer.stop(0);
executor.shutdownNow();
Expand Down
Expand Up @@ -404,6 +404,8 @@ public void failBadCredentials() throws IOException {

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

1 comment on commit 8ea0606

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.