If things go wrong, don't wait forever for the latch.
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 1 Jul 2011 14:05:00 +0000 (14:05 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 1 Jul 2011 14:05:00 +0000 (14:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1141944 13f79535-47bb-0310-9956-ffa450edef68

test/org/apache/catalina/core/TestStandardWrapper.java

index e43be0e..d8159ab 100644 (file)
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import javax.servlet.Servlet;
 import javax.servlet.ServletConfig;
@@ -455,6 +456,7 @@ public class TestStandardWrapper extends TomcatBaseTest {
             implements javax.servlet.SingleThreadModel {
 
         private static final long serialVersionUID = 1L;
+        private static final long LATCH_TIMEOUT = 60;
 
         private int data = 0;
 
@@ -462,16 +464,22 @@ public class TestStandardWrapper extends TomcatBaseTest {
         protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                 throws ServletException, IOException {
 
+            boolean latchAwaitResult = false;
+            
             // Ensure all threads have their own instance of the servlet
             latch.countDown();
             try {
-                latch.await();
+                latchAwaitResult = latch.await(LATCH_TIMEOUT, TimeUnit.SECONDS);
             } catch (InterruptedException e) {
                 // Ignore
             }
 
             resp.setContentType("text/plain");
-            resp.getWriter().print(data);
+            if (latchAwaitResult) {
+                resp.getWriter().print(data);
+            } else {
+                resp.getWriter().print("Latch await failed");
+            }
             resp.getWriter().print(",");
             resp.getWriter().print(hashCode());
         }