From f122e75dd6851df33cecd1fe2bd4071d9b791e68 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 6 Dec 2022 14:29:51 +0100 Subject: [PATCH 1/3] Reduced test load and increased timeout to avoid flakyness in Jenkins. Signed-off-by: Simone Bordet --- .../java/org/eclipse/jetty/client/ConnectionPoolTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/ConnectionPoolTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/ConnectionPoolTest.java index ab7def6ba4d0..5af5a43a50f6 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/ConnectionPoolTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/ConnectionPoolTest.java @@ -379,7 +379,7 @@ public void resolve(String host, int port, Promise> prom @MethodSource("pools") public void testConcurrentRequestsAllBlockedOnServerWithLargeConnectionPool(ConnectionPoolFactory factory) throws Exception { - int count = 50; + int count = 10; testConcurrentRequestsAllBlockedOnServer(factory, count, 2 * count); } @@ -387,7 +387,7 @@ public void testConcurrentRequestsAllBlockedOnServerWithLargeConnectionPool(Conn @MethodSource("pools") public void testConcurrentRequestsAllBlockedOnServerWithExactConnectionPool(ConnectionPoolFactory factory) throws Exception { - int count = 50; + int count = 10; testConcurrentRequestsAllBlockedOnServer(factory, count, count); } @@ -441,10 +441,12 @@ protected void service(String target, org.eclipse.jetty.server.Request jettyRequ { if (result.isSucceeded()) latch.countDown(); + else + result.getFailure().printStackTrace(); })); } - assertTrue(latch.await(5, TimeUnit.SECONDS), "server requests " + barrier.getNumberWaiting() + "<" + count + " - client: " + client.dump()); + assertTrue(latch.await(15, TimeUnit.SECONDS), "server requests " + barrier.getNumberWaiting() + "<" + count + " - client: " + client.dump()); List destinations = client.getDestinations(); assertEquals(1, destinations.size()); // The max duration connection pool aggressively closes expired connections upon release, which interferes with this assertion. From a546027db8ea138b2cc9f21b4c4505b828931c34 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 6 Dec 2022 15:29:05 +0100 Subject: [PATCH 2/3] Fixes #9006 - WebSocket MessageInputStream.read() returns signed byte Now properly coverting to `int`. Added test. Also fixed MultiPartInputStreamParser.Base64InputStream for the same issue. Signed-off-by: Simone Bordet --- .../server/MultiPartInputStreamParser.java | 2 +- .../internal/messages/MessageInputStream.java | 2 +- .../common/MessageInputStreamTest.java | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartInputStreamParser.java b/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartInputStreamParser.java index acbd940ce2c0..a8fe2bf15c33 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartInputStreamParser.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartInputStreamParser.java @@ -941,7 +941,7 @@ else if (_line.length() == 0) _pos = 0; } - return _buffer[_pos++]; + return _buffer[_pos++] & 0xFF; } } } diff --git a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/messages/MessageInputStream.java b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/messages/MessageInputStream.java index 12b20ce350f0..d670440c87fd 100644 --- a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/messages/MessageInputStream.java +++ b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/messages/MessageInputStream.java @@ -87,7 +87,7 @@ public int read() throws IOException if (len < 0) // EOF return -1; if (len > 0) // did read something - return buf[0]; + return buf[0] & 0xFF; // reading nothing (len == 0) tries again } } diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/MessageInputStreamTest.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/MessageInputStreamTest.java index 74929abe8b5a..e22965db5edc 100644 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/MessageInputStreamTest.java +++ b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/MessageInputStreamTest.java @@ -33,6 +33,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTimeout; @@ -279,4 +280,23 @@ public void testAppendNullPayloadRead() throws IOException } }); } + + @Test + public void testReadSingleByteIsNotSigned() throws Exception + { + try (MessageInputStream stream = new MessageInputStream()) + { + // Byte must be greater than 127. + int theByte = 200; + // Append a single message (simple, short) + Frame frame = new Frame(OpCode.BINARY); + frame.setPayload(new byte[]{(byte)theByte}); + frame.setFin(true); + stream.accept(frame, Callback.NOOP); + + // Single byte read must not return a signed byte. + int read = stream.read(); + assertEquals(theByte, read); + } + } } From 7c757689a2f429ad8aef986c13c6278388e8493b Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 6 Dec 2022 15:48:36 +0100 Subject: [PATCH 3/3] Fixes #9009 - Flaky test StreamCloseTest.testRequestDataClosedResponseDataClosedClosesStream. Regression introduced by #8678. Now using awaitility to wait for the stream count to go to zero. Signed-off-by: Simone Bordet --- .../java/org/eclipse/jetty/http2/client/StreamCloseTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamCloseTest.java b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamCloseTest.java index 5dc0beb00c91..1cd02492f09b 100644 --- a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamCloseTest.java +++ b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamCloseTest.java @@ -14,6 +14,7 @@ package org.eclipse.jetty.http2.client; import java.nio.ByteBuffer; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -38,6 +39,8 @@ import org.eclipse.jetty.util.Promise; import org.junit.jupiter.api.Test; +import static org.awaitility.Awaitility.await; +import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -179,7 +182,7 @@ public void succeeded() assertTrue(serverDataLatch.await(5, TimeUnit.SECONDS)); assertTrue(completeLatch.await(5, TimeUnit.SECONDS)); assertTrue(stream.isClosed()); - assertEquals(0, stream.getSession().getStreams().size()); + await().atMost(Duration.ofSeconds(5)).until(() -> stream.getSession().getStreams().size(), equalTo(0)); } @Test