From f170191003152e23b4da368105ebcc898ce2a590 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 24 Jan 2019 10:12:36 +1100 Subject: [PATCH] Fix problems with close unit tests before creating open unit tests Signed-off-by: Greg Wilkins --- .../websocket/core/WebSocketCloseTest.java | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java index 1bd0b5478cc..1fd58625186 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java @@ -88,7 +88,13 @@ public class WebSocketCloseTest extends WebSocketTester assertTrue(server.handler.opened.await(10, TimeUnit.SECONDS)); - assertThat(server.handler.getCoreSession().toString(), containsString("OPEN")); + assertThat(server.handler.state, containsString("CONNECTED")); + while(true) + { + Thread.yield(); + if (server.handler.getCoreSession().toString().contains("OPEN")) + break; + } LOG.info("Server: OPEN"); break; @@ -102,6 +108,12 @@ public class WebSocketCloseTest extends WebSocketTester client = newClient(server.getLocalPort()); assertTrue(server.handler.opened.await(10, TimeUnit.SECONDS)); + while(true) + { + Thread.yield(); + if (server.handler.getCoreSession().toString().contains("OPEN")) + break; + } server.handler.getCoreSession().demand(1); client.getOutputStream().write(RawFrameBuilder.buildClose(new CloseStatus(CloseStatus.NORMAL), true)); @@ -123,6 +135,12 @@ public class WebSocketCloseTest extends WebSocketTester client = newClient(server.getLocalPort()); assertTrue(server.handler.opened.await(10, TimeUnit.SECONDS)); + while(true) + { + Thread.yield(); + if (server.handler.getCoreSession().toString().contains("OPEN")) + break; + } server.sendFrame(CloseStatus.toFrame(CloseStatus.NORMAL)); Frame frame = receiveFrame(client.getInputStream()); @@ -138,7 +156,7 @@ public class WebSocketCloseTest extends WebSocketTester } @Test - public void serverClose_ICLOSED() throws Exception + public void serverClose_ISHUT() throws Exception { setup(State.ISHUT); @@ -152,7 +170,7 @@ public class WebSocketCloseTest extends WebSocketTester } @Test - public void serverDifferentClose_ICLOSED() throws Exception + public void serverDifferentClose_ISHUT() throws Exception { setup(State.ISHUT); @@ -167,7 +185,7 @@ public class WebSocketCloseTest extends WebSocketTester } @Test - public void serverFailClose_ICLOSED() throws Exception + public void serverFailClose_ISHUT() throws Exception { try (StacklessLogging stackless = new StacklessLogging(WebSocketChannel.class)) { @@ -184,7 +202,7 @@ public class WebSocketCloseTest extends WebSocketTester } @Test - public void clientClose_OCLOSED() throws Exception + public void clientClose_OSHUT() throws Exception { setup(State.OSHUT); server.handler.getCoreSession().demand(1); @@ -199,7 +217,7 @@ public class WebSocketCloseTest extends WebSocketTester } @Test - public void clientDifferentClose_OCLOSED() throws Exception + public void clientDifferentClose_OSHUT() throws Exception { setup(State.OSHUT); server.handler.getCoreSession().demand(1); @@ -214,7 +232,7 @@ public class WebSocketCloseTest extends WebSocketTester } @Test - public void clientCloseServerFailClose_OCLOSED() throws Exception + public void clientCloseServerFailClose_OSHUT() throws Exception { try (StacklessLogging stackless = new StacklessLogging(WebSocketChannel.class)) { @@ -244,7 +262,7 @@ public class WebSocketCloseTest extends WebSocketTester } @Test - public void clientSendsBadFrame_OCLOSED() throws Exception + public void clientSendsBadFrame_OSHUT() throws Exception { setup(State.OSHUT); @@ -256,7 +274,7 @@ public class WebSocketCloseTest extends WebSocketTester } @Test - public void clientSendsBadFrame_ICLOSED() throws Exception + public void clientSendsBadFrame_ISHUT() throws Exception { setup(State.ISHUT); @@ -284,7 +302,7 @@ public class WebSocketCloseTest extends WebSocketTester } @Test - public void clientAborts_OCLOSED() throws Exception + public void clientAborts_OSHUT() throws Exception { setup(State.OSHUT); @@ -297,7 +315,7 @@ public class WebSocketCloseTest extends WebSocketTester } @Test - public void clientAborts_ICLOSED() throws Exception + public void clientAborts_ISHUT() throws Exception { setup(State.ISHUT); @@ -328,7 +346,7 @@ public class WebSocketCloseTest extends WebSocketTester } @Test - public void onFrameThrows_OCLOSED() throws Exception + public void onFrameThrows_OSHUT() throws Exception { setup(State.OSHUT); @@ -347,6 +365,7 @@ public class WebSocketCloseTest extends WebSocketTester static class TestFrameHandler implements FrameHandler { private CoreSession session; + String state; protected BlockingQueue receivedFrames = new BlockingArrayQueue<>(); protected BlockingQueue receivedCallback = new BlockingArrayQueue<>(); @@ -368,7 +387,8 @@ public class WebSocketCloseTest extends WebSocketTester public void onOpen(CoreSession coreSession) { LOG.info("onOpen {}", coreSession); - this.session = coreSession; + session = coreSession; + state = session.toString(); opened.countDown(); } @@ -376,6 +396,7 @@ public class WebSocketCloseTest extends WebSocketTester public void onFrame(Frame frame, Callback callback) { LOG.info("onFrame: " + BufferUtil.toDetailString(frame.getPayload())); + state = session.toString(); receivedCallback.offer(callback); receivedFrames.offer(Frame.copy(frame)); @@ -387,6 +408,7 @@ public class WebSocketCloseTest extends WebSocketTester public void onClosed(CloseStatus closeStatus) { LOG.info("onClosed {}", closeStatus); + state = session.toString(); this.closeStatus = closeStatus; closed.countDown(); } @@ -395,6 +417,7 @@ public class WebSocketCloseTest extends WebSocketTester public void onError(Throwable cause) throws Exception { LOG.info("onError {} ", cause == null?null:cause.toString()); + state = session.toString(); } @Override @@ -410,6 +433,7 @@ public class WebSocketCloseTest extends WebSocketTester frame.setPayload(text); getCoreSession().sendFrame(frame, NOOP, false); + state = session.toString(); } }