Author: markt
Date: Tue Apr 26 09:32:15 2016
New Revision: 1740977

URL: http://svn.apache.org/viewvc?rev=1740977&view=rev
Log:
Align test implementation more closely with trunk to try and reduce instances 
of Gump CI failures.

Modified:
    
tomcat/tc8.0.x/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java

Modified: 
tomcat/tc8.0.x/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java?rev=1740977&r1=1740976&r2=1740977&view=diff
==============================================================================
--- 
tomcat/tc8.0.x/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
 (original)
+++ 
tomcat/tc8.0.x/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
 Tue Apr 26 09:32:15 2016
@@ -71,6 +71,9 @@ public class TestWsWebSocketContainer ex
     private static final long TIMEOUT_MS = 5 * 1000;
     private static final long MARGIN = 500;
 
+    // 5s should be plenty but Gump can be a lot slower
+    private static final long START_STOP_WAIT = 60 * 1000;
+
     static {
         StringBuilder sb = new StringBuilder(4096);
         for (int i = 0; i < 4096; i++) {
@@ -345,9 +348,9 @@ public class TestWsWebSocketContainer ex
         Exception exception = null;
         try {
             while (true) {
+                lastSend = System.currentTimeMillis();
                 Future<Void> f = wsSession.getAsyncRemote().sendBinary(
                         ByteBuffer.wrap(MESSAGE_BINARY_4K));
-                lastSend = System.currentTimeMillis();
                 f.get();
             }
         } catch (Exception e) {
@@ -356,8 +359,8 @@ public class TestWsWebSocketContainer ex
 
         long timeout = System.currentTimeMillis() - lastSend;
 
-        // Clear the server side block and prevent any further blocks to allow
-        // the server to shutdown cleanly
+        // Clear the server side block and prevent further blocks to allow the
+        // server to shutdown cleanly
         BlockingPojo.clearBlock();
 
         // Close the client session, primarily to allow the
@@ -924,6 +927,9 @@ public class TestWsWebSocketContainer ex
 
         Session s = connectToEchoServer(wsContainer, new EndpointA(), path);
 
+        // One for the client, one for the server
+        validateBackgroundProcessCount(2);
+
         StringBuilder msg = new StringBuilder();
         for (long i = 0; i < size; i++) {
             msg.append('x');
@@ -931,7 +937,7 @@ public class TestWsWebSocketContainer ex
 
         s.getBasicRemote().sendText(msg.toString());
 
-        // Wait for up to 5 seconds for session to close
+        // Wait for up to 5 seconds for the client session to open
         boolean open = s.isOpen();
         int count = 0;
         while (open != expectOpen && count < 50) {
@@ -942,9 +948,30 @@ public class TestWsWebSocketContainer ex
 
         Assert.assertEquals(Boolean.valueOf(expectOpen),
                 Boolean.valueOf(s.isOpen()));
+
+        // Close the session if it is expected to be open
+        if (expectOpen) {
+            s.close();
+        }
+
+        // Ensure both server and client have shutdown
+        validateBackgroundProcessCount(0);
     }
 
 
+    private void validateBackgroundProcessCount(int expected) throws Exception 
{
+        int count = 0;
+        while (count < (START_STOP_WAIT / 100)) {
+            if (BackgroundProcessManager.getInstance().getProcessCount() == 
expected) {
+                break;
+            }
+            Thread.sleep(100);
+            count++;
+        }
+        Assert.assertEquals(expected, 
BackgroundProcessManager.getInstance().getProcessCount());
+
+    }
+
     @Test
     public void testPerMessageDefalteClient01() throws Exception {
         doTestPerMessageDefalteClient(MESSAGE_STRING_1, 1);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to