Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
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 8ea0606aba15911f5bfe2c81a83b42288d97095f
@@ -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);
@@ -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 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();
}
}
@@ -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)
@@ -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 void pendingBinaryPingClose(boolean last) throws Exception {
repeatable(() -> {
server = Support.notReadingServer();
server.setReceiveBufferSize(1024);
server.open();
webSocket = httpClient().newWebSocketBuilder()
.buildAsync(server.getURI(), new WebSocket.Listener() { })
@@ -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 void pendingBinaryPongClose(boolean last) throws Exception {
repeatable(() -> {
server = Support.notReadingServer();
server.setReceiveBufferSize(1024);
server.open();
webSocket = httpClient().newWebSocketBuilder()
.buildAsync(server.getURI(), new WebSocket.Listener() { })
@@ -25,6 +25,7 @@
* @test
* @build DummyWebSocketServer
* @run testng/othervm
* -Djdk.httpclient.sendBufferSize=8192
* PendingPingBinaryClose
*/

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

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

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

@@ -50,6 +51,7 @@
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() { })
@@ -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 void pendingTextPongClose(boolean last) throws Exception {
repeatable(() -> {
server = Support.notReadingServer();
server.setReceiveBufferSize(1024);
server.open();
webSocket = httpClient().newWebSocketBuilder()
.buildAsync(server.getURI(), new WebSocket.Listener() { })
@@ -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 @@ 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++) {
@@ -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 @@
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 @@ 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()
@@ -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();
@@ -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();
@@ -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

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 8ea0606 Jun 16, 2021

Please sign in to comment.