Reducing test logging noise by squelching stack traces in test cases where they are expected

This commit is contained in:
Joakim Erdfelt 2012-12-21 14:22:10 -07:00
parent 1936a0fc51
commit 5b7c19e38d
11 changed files with 133 additions and 17 deletions

View File

@ -25,13 +25,16 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception;
import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.util.log.StdErrLog;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.blockhead.BlockheadClient;
import org.eclipse.jetty.websocket.server.helper.IncomingFramesCapture;
@ -42,12 +45,14 @@ import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test various <a href="http://tools.ietf.org/html/rfc6455">RFC 6455</a> specified requirements placed on {@link WebSocketServlet}
* <p>
* This test serves a different purpose than than the {@link WebSocketMessageRFC6455Test}, and {@link WebSocketParserRFC6455Test} tests.
*/
@RunWith(AdvancedRunner.class)
public class WebSocketServletRFCTest
{
private static Generator generator = new UnitGenerator();
@ -66,6 +71,12 @@ public class WebSocketServletRFCTest
server.stop();
}
private void enableStacks(Class<?> clazz, boolean enabled)
{
StdErrLog log = StdErrLog.getLogger(clazz);
log.setHideStacks(!enabled);
}
/**
* Test that aggregation of binary frames into a single message occurs
*/
@ -324,6 +335,9 @@ public class WebSocketServletRFCTest
@Test
public void testTextNotUTF8() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
BlockheadClient client = new BlockheadClient(server.getServerUri());
client.setProtocols("other");
try
@ -347,8 +361,9 @@ public class WebSocketServletRFCTest
}
finally
{
// Reenable Long Stacks from Parser
enableStacks(Parser.class,true);
client.close();
}
}
}

View File

@ -23,6 +23,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.StdErrLog;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.Generator;
import org.eclipse.jetty.websocket.server.SimpleServletServer;
@ -88,6 +89,12 @@ public abstract class AbstractABCase
@Rule
public TestName testname = new TestName();
protected void enableStacks(Class<?> clazz, boolean enabled)
{
StdErrLog log = StdErrLog.getLogger(clazz);
log.setHideStacks(!enabled);
}
public Generator getLaxGenerator()
{
return laxGenerator;

View File

@ -190,6 +190,7 @@ public class Fuzzer
// we expect that the close handshake to have occurred and the server should have closed the connection
try
{
@SuppressWarnings("unused")
int val = client.read();
Assert.fail("Server has not closed socket");

View File

@ -22,13 +22,17 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AdvancedRunner.class)
public class TestABCase2 extends AbstractABCase
{
/**
@ -232,6 +236,9 @@ public class TestABCase2 extends AbstractABCase
@Test
public void testCase2_5() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
byte payload[] = new byte[126]; // intentionally too big
Arrays.fill(payload,(byte)'5');
@ -253,6 +260,7 @@ public class TestABCase2 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}

View File

@ -22,13 +22,34 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test various RSV violations
*/
@RunWith(AdvancedRunner.class)
public class TestABCase3 extends AbstractABCase
{
@After
public void enableParserStacks()
{
enableStacks(Parser.class,true);
}
@Before
public void quietParserStacks()
{
enableStacks(Parser.class,false);
}
/**
* Send small text frame, with RSV1 == true, with no extensions defined.
*/

View File

@ -21,12 +21,21 @@ package org.eclipse.jetty.websocket.server.ab;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test various bad / forbidden opcodes (per spec)
*/
@RunWith(AdvancedRunner.class)
public class TestABCase4 extends AbstractABCase
{
// Allow Fuzzer / Generator to create bad frames for testing frame validation
@ -40,6 +49,18 @@ public class TestABCase4 extends AbstractABCase
}
}
@After
public void enableParserStacks()
{
enableStacks(Parser.class,true);
}
@Before
public void quietParserStacks()
{
enableStacks(Parser.class,false);
}
/**
* Send opcode 3 (reserved)
*/

View File

@ -27,6 +27,7 @@ import org.eclipse.jetty.toolchain.test.annotation.Slow;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -43,6 +44,9 @@ public class TestABCase5 extends AbstractABCase
@Test
public void testCase5_1() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new WebSocketFrame(OpCode.PING).setPayload("hello, ").setFin(false));
send.add(new WebSocketFrame(OpCode.CONTINUATION).setPayload("world"));
@ -62,6 +66,7 @@ public class TestABCase5 extends AbstractABCase
finally
{
fuzzer.close();
enableStacks(Parser.class,true);
}
}
@ -71,6 +76,9 @@ public class TestABCase5 extends AbstractABCase
@Test
public void testCase5_10() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new WebSocketFrame(OpCode.CONTINUATION).setPayload("sorry").setFin(true));
send.add(new WebSocketFrame(OpCode.TEXT).setPayload("hello, world"));
@ -89,6 +97,7 @@ public class TestABCase5 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}
@ -99,6 +108,9 @@ public class TestABCase5 extends AbstractABCase
@Test
public void testCase5_11() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new WebSocketFrame(OpCode.CONTINUATION).setPayload("sorry").setFin(true));
send.add(new WebSocketFrame(OpCode.TEXT).setPayload("hello, world"));
@ -118,6 +130,7 @@ public class TestABCase5 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}
@ -128,6 +141,9 @@ public class TestABCase5 extends AbstractABCase
@Test
public void testCase5_12() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new WebSocketFrame(OpCode.CONTINUATION).setPayload("sorry").setFin(false));
send.add(new WebSocketFrame(OpCode.TEXT).setPayload("hello, world"));
@ -146,6 +162,7 @@ public class TestABCase5 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}
@ -156,6 +173,8 @@ public class TestABCase5 extends AbstractABCase
@Test
public void testCase5_13() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new WebSocketFrame(OpCode.CONTINUATION).setPayload("sorry").setFin(false));
send.add(new WebSocketFrame(OpCode.TEXT).setPayload("hello, world"));
@ -174,6 +193,7 @@ public class TestABCase5 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}
@ -184,6 +204,9 @@ public class TestABCase5 extends AbstractABCase
@Test
public void testCase5_14() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new WebSocketFrame(OpCode.CONTINUATION).setPayload("sorry").setFin(false));
send.add(new WebSocketFrame(OpCode.TEXT).setPayload("hello, world"));
@ -203,6 +226,7 @@ public class TestABCase5 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,false);
fuzzer.close();
}
}
@ -213,6 +237,9 @@ public class TestABCase5 extends AbstractABCase
@Test
public void testCase5_15() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new WebSocketFrame(OpCode.TEXT).setPayload("fragment1").setFin(false));
send.add(new WebSocketFrame(OpCode.CONTINUATION).setPayload("fragment2").setFin(true));
@ -234,6 +261,7 @@ public class TestABCase5 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}
@ -244,6 +272,9 @@ public class TestABCase5 extends AbstractABCase
@Test
public void testCase5_16() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new WebSocketFrame(OpCode.CONTINUATION).setPayload("fragment1").setFin(false)); // bad frame
send.add(new WebSocketFrame(OpCode.TEXT).setPayload("fragment2").setFin(false));
@ -266,6 +297,7 @@ public class TestABCase5 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}
@ -276,6 +308,9 @@ public class TestABCase5 extends AbstractABCase
@Test
public void testCase5_17() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new WebSocketFrame(OpCode.CONTINUATION).setPayload("fragment1").setFin(true)); // nothing to continue
send.add(new WebSocketFrame(OpCode.TEXT).setPayload("fragment2").setFin(false));
@ -298,6 +333,7 @@ public class TestABCase5 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}
@ -308,6 +344,9 @@ public class TestABCase5 extends AbstractABCase
@Test
public void testCase5_18() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new WebSocketFrame(OpCode.TEXT).setPayload("fragment1").setFin(false));
send.add(new WebSocketFrame(OpCode.TEXT).setPayload("fragment2").setFin(true)); // bad frame, must be continuation
@ -326,6 +365,7 @@ public class TestABCase5 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}
@ -388,6 +428,9 @@ public class TestABCase5 extends AbstractABCase
@Test
public void testCase5_2() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new WebSocketFrame(OpCode.PONG).setPayload("hello, ").setFin(false));
send.add(new WebSocketFrame(OpCode.CONTINUATION).setPayload("world"));
@ -406,6 +449,7 @@ public class TestABCase5 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}
@ -691,6 +735,9 @@ public class TestABCase5 extends AbstractABCase
@Test
public void testCase5_9() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new WebSocketFrame(OpCode.CONTINUATION).setPayload("sorry").setFin(true));
send.add(new WebSocketFrame(OpCode.TEXT).setPayload("hello, world"));
@ -709,6 +756,7 @@ public class TestABCase5 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}

View File

@ -31,6 +31,7 @@ import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.server.helper.Hex;
import org.junit.Test;
@ -356,6 +357,9 @@ public class TestABCase6 extends AbstractABCase
@Slow
public void testCase6_4_3() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
ByteBuffer payload = ByteBuffer.allocate(64);
BufferUtil.clearToFill(payload);
payload.put(TypeUtil.fromHexString("cebae1bdb9cf83cebcceb5")); // good
@ -400,6 +404,7 @@ public class TestABCase6 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}
@ -411,6 +416,9 @@ public class TestABCase6 extends AbstractABCase
@Slow
public void testCase6_4_4() throws Exception
{
// Disable Long Stacks from Parser (we know this test will throw an exception)
enableStacks(Parser.class,false);
byte invalid[] = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F49080808080656469746564");
List<WebSocketFrame> send = new ArrayList<>();
@ -437,6 +445,7 @@ public class TestABCase6 extends AbstractABCase
}
finally
{
enableStacks(Parser.class,true);
fuzzer.close();
}
}

View File

@ -24,7 +24,6 @@ import java.util.List;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.log.StdErrLog;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
@ -177,10 +176,4 @@ public class TestABCase6_BadUTF extends AbstractABCase
enableStacks(Parser.class,true);
}
}
private void enableStacks(Class<?> clazz, boolean enabled)
{
StdErrLog log = StdErrLog.getLogger(clazz);
log.setHideStacks(!enabled);
}
}

View File

@ -26,7 +26,6 @@ import java.util.List;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.StdErrLog;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.OpCode;
@ -41,12 +40,6 @@ import org.junit.Test;
*/
public class TestABCase7 extends AbstractABCase
{
private static void enableStacks(Class<?> clazz, boolean enabled)
{
StdErrLog log = StdErrLog.getLogger(clazz);
log.setHideStacks(!enabled);
}
@Rule
public TestTracker tt = new TestTracker();

View File

@ -1,8 +1,8 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
# org.eclipse.jetty.LEVEL=WARN
org.eclipse.jetty.LEVEL=WARN
# org.eclipse.jetty.websocket.LEVEL=DEBUG
org.eclipse.jetty.websocket.LEVEL=WARN
# org.eclipse.jetty.websocket.LEVEL=WARN
# org.eclipse.jetty.websocket.common.io.LEVEL=DEBUG
# org.eclipse.jetty.websocket.server.ab.LEVEL=DEBUG
# org.eclipse.jetty.websocket.common.io.LEVEL=DEBUG