Author: rjung
Date: Wed Dec 18 14:38:35 2013
New Revision: 1551955

URL: http://svn.apache.org/r1551955
Log:
Sync TestWsSubprotocols with trunk to prevent
occasional test failures.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWsSubprotocols.java

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1524978,1551953

Modified: 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWsSubprotocols.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWsSubprotocols.java?rev=1551955&r1=1551954&r2=1551955&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWsSubprotocols.java 
(original)
+++ 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWsSubprotocols.java 
Wed Dec 18 14:38:35 2013
@@ -72,11 +72,6 @@ public class TestWsSubprotocols extends 
                         .build(), new URI("ws://localhost:" + getPort()
                         + SubProtocolsEndpoint.PATH_BASIC));
 
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException e) {
-            // Ignore
-        }
         Assert.assertTrue(wsSession.isOpen());
         if (wsSession.getNegotiatedSubprotocol() != null) {
             Assert.assertTrue(wsSession.getNegotiatedSubprotocol().isEmpty());
@@ -90,13 +85,16 @@ public class TestWsSubprotocols extends 
                         .build(), new URI("ws://localhost:" + getPort()
                         + SubProtocolsEndpoint.PATH_BASIC));
 
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException e) {
-            // Ignore
-        }
         Assert.assertTrue(wsSession.isOpen());
         Assert.assertEquals("sp2", wsSession.getNegotiatedSubprotocol());
+        // Client thread might move faster than server. Wait for upto 5s for 
the
+        // subProtocols to be set
+        int count = 0;
+        while (count < 50 && SubProtocolsEndpoint.subprotocols == null) {
+            count++;
+            Thread.sleep(100);
+        }
+        Assert.assertNotNull(SubProtocolsEndpoint.subprotocols);
         Assert.assertArrayEquals(new String[]{"sp1","sp2"},
                 SubProtocolsEndpoint.subprotocols.toArray(new String[2]));
         wsSession.close();
@@ -106,7 +104,7 @@ public class TestWsSubprotocols extends 
     @ServerEndpoint(value = "/echo", subprotocols = {"sp1","sp2"})
     public static class SubProtocolsEndpoint {
         public static String PATH_BASIC = "/echo";
-        public static List<String> subprotocols;
+        public static volatile List<String> subprotocols;
 
         @OnOpen
         public void processOpen(@SuppressWarnings("unused") Session session,



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

Reply via email to