Merge pull request #10774 from jetty/jetty-12.0.x-10346-JsrEchoTest

Issue #10346 - fix bug in NetworkFuzzer to de-flake JsrEchoTest
This commit is contained in:
Lachlan 2023-10-30 17:13:46 +11:00 committed by GitHub
commit 8ac8da777c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View File

@ -29,6 +29,7 @@ import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.thread.AutoLock;
import org.eclipse.jetty.websocket.core.Behavior;
import org.eclipse.jetty.websocket.core.CloseStatus;
import org.eclipse.jetty.websocket.core.CoreSession;
@ -214,9 +215,10 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
public static class FrameCapture implements FrameHandler
{
private final BlockingQueue<Frame> receivedFrames = new LinkedBlockingQueue<>();
private final CountDownLatch openLatch = new CountDownLatch(1);
private EndPoint endPoint;
private CountDownLatch openLatch = new CountDownLatch(1);
private CoreSession coreSession;
private final AutoLock lock = new AutoLock();
public void setEndPoint(EndPoint endpoint)
{
@ -235,8 +237,11 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
@Override
public void onFrame(Frame frame, Callback callback)
{
receivedFrames.offer(Frame.copy(frame));
callback.succeeded();
try (AutoLock ignored = lock.lock())
{
receivedFrames.add(Frame.copy(frame));
callback.succeeded();
}
coreSession.demand();
}
@ -263,7 +268,7 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
throw new IOException(e);
}
synchronized (this)
try (AutoLock ignored = lock.lock())
{
FutureCallback callback = new FutureCallback();
endPoint.write(callback, buffer);

View File

@ -29,6 +29,7 @@ import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.thread.AutoLock;
import org.eclipse.jetty.websocket.core.Behavior;
import org.eclipse.jetty.websocket.core.CloseStatus;
import org.eclipse.jetty.websocket.core.CoreSession;
@ -214,9 +215,10 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
public static class FrameCapture implements FrameHandler
{
private final BlockingQueue<Frame> receivedFrames = new LinkedBlockingQueue<>();
private final CountDownLatch openLatch = new CountDownLatch(1);
private EndPoint endPoint;
private CountDownLatch openLatch = new CountDownLatch(1);
private CoreSession coreSession;
private final AutoLock lock = new AutoLock();
public void setEndPoint(EndPoint endpoint)
{
@ -235,8 +237,11 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
@Override
public void onFrame(Frame frame, Callback callback)
{
receivedFrames.offer(Frame.copy(frame));
callback.succeeded();
try (AutoLock ignored = lock.lock())
{
receivedFrames.add(Frame.copy(frame));
callback.succeeded();
}
coreSession.demand();
}
@ -263,7 +268,7 @@ public class NetworkFuzzer extends Fuzzer.Adapter implements Fuzzer, AutoCloseab
throw new IOException(e);
}
synchronized (this)
try (AutoLock ignored = lock.lock())
{
FutureCallback callback = new FutureCallback();
endPoint.write(callback, buffer);