You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/02/20 22:00:04 UTC

svn commit: r1661222 - in /tomcat/trunk: java/org/apache/tomcat/websocket/BackgroundProcessManager.java test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java

Author: markt
Date: Fri Feb 20 21:00:04 2015
New Revision: 1661222

URL: http://svn.apache.org/r1661222
Log:
Close the client and server sessions after each test to ensure that the background process stops and reduce the chances of one test interfering with an other. This also simplifies debugging should a test fail.

Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/BackgroundProcessManager.java
    tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/BackgroundProcessManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/BackgroundProcessManager.java?rev=1661222&r1=1661221&r2=1661222&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/BackgroundProcessManager.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/BackgroundProcessManager.java Fri Feb 20 21:00:04 2015
@@ -98,6 +98,16 @@ public class BackgroundProcessManager {
     }
 
 
+    /*
+     * For unit testing.
+     */
+    int getProcessCount() {
+        synchronized (processesLock) {
+            return processes.size();
+        }
+    }
+
+
     private static class WsBackgroundThread extends Thread {
 
         private final BackgroundProcessManager manager;

Modified: tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java?rev=1661222&r1=1661221&r2=1661222&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java Fri Feb 20 21:00:04 2015
@@ -900,7 +900,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 close
         boolean open = s.isOpen();
         int count = 0;
         while (open != expectOpen && count < 50) {
@@ -911,6 +911,23 @@ 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();
+        }
+
+        // Wait for up to 5 seconds for the server session to close and the
+        // background process to stop
+        count = 0;
+        while (count < 50) {
+            if (BackgroundProcessManager.getInstance().getProcessCount() == 0) {
+                break;
+            }
+            Thread.sleep(100);
+        }
+
+        Assert.assertEquals(0, BackgroundProcessManager.getInstance().getProcessCount());
     }
 
 



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