diff --git a/jetty-websocket/pom.xml b/jetty-websocket/pom.xml index 4adbece5a50..1bc5214b513 100644 --- a/jetty-websocket/pom.xml +++ b/jetty-websocket/pom.xml @@ -41,10 +41,9 @@ jetty-http ${project.version} - - junit - junit + org.eclipse.jetty.toolchain + jetty-test-helper test diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketClientTest.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketClientTest.java index 987303bdae0..f8029ffb11f 100644 --- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketClientTest.java +++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketClientTest.java @@ -1,5 +1,7 @@ package org.eclipse.jetty.websocket; +import static org.hamcrest.Matchers.*; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -518,7 +520,7 @@ public class WebSocketClientTest Assert.assertTrue(open.get()); Assert.assertEquals(0,close.get()); - final int messages=20000; + final int messages=200000; final AtomicLong totalB=new AtomicLong(); Thread consumer = new Thread() @@ -526,9 +528,10 @@ public class WebSocketClientTest @Override public void run() { + // Thread.sleep is for artificially poor performance reader needed for this testcase. try { - Thread.sleep(2000); + Thread.sleep(200); byte[] recv = new byte[32*1024]; int len=0; @@ -552,26 +555,23 @@ public class WebSocketClientTest consumer.start(); // Send lots of messages client to server - long max=0; long start=System.currentTimeMillis(); String mesg="This is a test message to send"; for (int i=0;imax) - max=duration; - } + connection.sendMessage(mesg); } + // Duration for the write phase + long writeDur = (System.currentTimeMillis() - start); + // wait for consumer to complete - while (totalB.get()1000); // writing was blocked + } + + Assert.assertThat("write duration", writeDur, greaterThan(1000L)); // writing was blocked Assert.assertEquals(messages*(mesg.length()+6L),totalB.get()); consumer.interrupt(); @@ -640,14 +640,23 @@ public class WebSocketClientTest { try { - Thread.sleep(2000); - while(m.get()max) - max=duration; - } } - - while(consumer.isAlive()) + + while(consumer.isAlive()) + { Thread.sleep(10); + } + + // Duration of the read operation. + long readDur = (System.currentTimeMillis() - start); - - Assert.assertTrue(max>1000); // writing was blocked + Assert.assertThat("read duration", readDur, greaterThan(1000L)); // reading was blocked Assert.assertEquals(m.get(),messages); // Close with code