| author | Thomas Becker | 2012-05-22 12:16:12 (EDT) |
|---|---|---|
| committer | Thomas Becker | 2012-05-22 12:16:12 (EDT) |
| commit | b3713156067c24d12fdec03b8fe3a804a3af3815 (patch) (side-by-side diff) | |
| tree | fa8770d208e8349af3a9d0a4c13f49e4e37877d7 | |
| parent | ced2d9efd3d8932950b0c34c51b77a2b81c9981e (diff) | |
| download | org.eclipse.jetty.project-b3713156067c24d12fdec03b8fe3a804a3af3815.zip org.eclipse.jetty.project-b3713156067c24d12fdec03b8fe3a804a3af3815.tar.gz org.eclipse.jetty.project-b3713156067c24d12fdec03b8fe3a804a3af3815.tar.bz2 | |
make spdy tests more reliable: fix race condition with goAway framerefs/changes/79/6079/1
Change-Id: I3bbdb8eee4a12f082f83730209bd0f8cf2fe7d03
| -rw-r--r-- | jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/ClosedStreamTest.java | 10 | ||||
| -rw-r--r-- | jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/ProtocolViolationsTest.java | 22 |
2 files changed, 20 insertions, 12 deletions
diff --git a/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/ClosedStreamTest.java b/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/ClosedStreamTest.java index c0c6a01..7b399f3 100644 --- a/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/ClosedStreamTest.java +++ b/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/ClosedStreamTest.java @@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.spdy.api.BytesDataInfo; import org.eclipse.jetty.spdy.api.DataInfo; +import org.eclipse.jetty.spdy.api.GoAwayInfo; import org.eclipse.jetty.spdy.api.Headers; import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.SPDY; @@ -180,6 +181,7 @@ public class ClosedStreamTest extends AbstractTest final CountDownLatch serverReplySentLatch = new CountDownLatch(1); final CountDownLatch clientReplyReceivedLatch = new CountDownLatch(1); final CountDownLatch serverDataReceivedLatch = new CountDownLatch(1); + final CountDownLatch goAwayReceivedLatch = new CountDownLatch(1); InetSocketAddress startServer = startServer(new ServerSessionFrameListener.Adapter() { @@ -206,6 +208,11 @@ public class ClosedStreamTest extends AbstractTest } }; } + @Override + public void onGoAway(Session session, GoAwayInfo goAwayInfo) + { + goAwayReceivedLatch.countDown(); + } }); final Generator generator = new Generator(new StandardByteBufferPool(),new StandardCompressionFactory().newCompressor()); @@ -214,6 +221,7 @@ public class ClosedStreamTest extends AbstractTest final SocketChannel socketChannel = SocketChannel.open(startServer); socketChannel.write(synData); + assertThat("synData is fully written", synData.hasRemaining(), is(false)); assertThat("server: syn reply is sent",serverReplySentLatch.await(5,TimeUnit.SECONDS),is(true)); @@ -263,6 +271,8 @@ public class ClosedStreamTest extends AbstractTest socketChannel.write(buffer); Assert.assertThat(buffer.hasRemaining(), is(false)); + assertThat("GoAway frame is received by server", goAwayReceivedLatch.await(5,TimeUnit.SECONDS), is(true)); + socketChannel.close(); } } diff --git a/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/ProtocolViolationsTest.java b/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/ProtocolViolationsTest.java index eb75be7..791b690 100644 --- a/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/ProtocolViolationsTest.java +++ b/jetty-spdy/spdy-jetty/src/test/java/org/eclipse/jetty/spdy/ProtocolViolationsTest.java @@ -1,5 +1,8 @@ package org.eclipse.jetty.spdy; +import static org.junit.Assert.*; +import static org.hamcrest.Matchers.*; + import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.ServerSocketChannel; @@ -15,7 +18,6 @@ import org.eclipse.jetty.spdy.api.RstInfo; import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.SessionFrameListener; -import org.eclipse.jetty.spdy.api.SessionStatus; import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.StreamFrameListener; import org.eclipse.jetty.spdy.api.StreamStatus; @@ -23,7 +25,6 @@ import org.eclipse.jetty.spdy.api.StringDataInfo; import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.frames.ControlFrameType; -import org.eclipse.jetty.spdy.frames.GoAwayFrame; import org.eclipse.jetty.spdy.frames.SynReplyFrame; import org.eclipse.jetty.spdy.generator.Generator; import org.junit.Assert; @@ -85,6 +86,7 @@ public class ProtocolViolationsTest extends AbstractTest byte[] bytes = new byte[1]; ByteBuffer writeBuffer = generator.data(streamId, bytes.length, new BytesDataInfo(bytes, true)); channel.write(writeBuffer); + assertThat("data is fully written", writeBuffer.hasRemaining(),is(false)); readBuffer.clear(); channel.read(readBuffer); @@ -92,11 +94,8 @@ public class ProtocolViolationsTest extends AbstractTest Assert.assertEquals(ControlFrameType.RST_STREAM.getCode(), readBuffer.getShort(2)); Assert.assertEquals(streamId, readBuffer.getInt(8)); - writeBuffer = generator.control(new GoAwayFrame(SPDY.V2, 0, SessionStatus.OK.getCode())); - channel.write(writeBuffer); - channel.shutdownOutput(); - channel.close(); - + session.goAway().get(5,TimeUnit.SECONDS); + server.close(); } @@ -129,7 +128,6 @@ public class ProtocolViolationsTest extends AbstractTest @Override public void onData(Stream stream, DataInfo dataInfo) { - System.out.println("ondata"); dataLatch.countDown(); } }); @@ -144,21 +142,21 @@ public class ProtocolViolationsTest extends AbstractTest ByteBuffer writeBuffer = generator.control(new SynReplyFrame(SPDY.V2, (byte)0, streamId, new Headers())); channel.write(writeBuffer); + assertThat("SynReply is fully written", writeBuffer.hasRemaining(), is(false)); byte[] bytes = new byte[1]; writeBuffer = generator.data(streamId, bytes.length, new BytesDataInfo(bytes, true)); channel.write(writeBuffer); + assertThat("data is fully written", writeBuffer.hasRemaining(), is(false)); // Write again to simulate the faulty condition writeBuffer.flip(); channel.write(writeBuffer); + assertThat("data is fully written", writeBuffer.hasRemaining(), is(false)); Assert.assertFalse(dataLatch.await(1, TimeUnit.SECONDS)); - writeBuffer = generator.control(new GoAwayFrame(SPDY.V2, 0, SessionStatus.OK.getCode())); - channel.write(writeBuffer); - channel.shutdownOutput(); - channel.close(); + session.goAway().get(5,TimeUnit.SECONDS); server.close(); } |

