Author: slaurent Date: Tue May 20 20:19:01 2014 New Revision: 1596390 URL: http://svn.apache.org/r1596390 Log: fixed timing and enclosed thread.join in a finally to avoid stopping the webapp before the request is finished (in case of assertion failure)
Modified: tomcat/trunk/test/org/apache/catalina/valves/TestStuckThreadDetectionValve.java Modified: tomcat/trunk/test/org/apache/catalina/valves/TestStuckThreadDetectionValve.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/valves/TestStuckThreadDetectionValve.java?rev=1596390&r1=1596389&r2=1596390&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/valves/TestStuckThreadDetectionValve.java (original) +++ tomcat/trunk/test/org/apache/catalina/valves/TestStuckThreadDetectionValve.java Tue May 20 20:19:01 2014 @@ -51,7 +51,7 @@ public class TestStuckThreadDetectionVal @Test public void testDetection() throws Exception { // second, we test the actual effect of the flag on the startup - StuckingServlet stuckingServlet = new StuckingServlet(5000L); + StuckingServlet stuckingServlet = new StuckingServlet(6000L); Wrapper servlet = Tomcat.addServlet(context, "myservlet", stuckingServlet); servlet.addMapping("/myservlet"); @@ -78,14 +78,15 @@ public class TestStuckThreadDetectionVal }; asyncThread.start(); - - Thread.sleep(1000L); - Assert.assertEquals(0, valve.getStuckThreadIds().length); - - Thread.sleep(2000L); - Assert.assertEquals(1, valve.getStuckThreadIds().length); - - asyncThread.join(); + try { + Thread.sleep(500L); + Assert.assertEquals(0, valve.getStuckThreadIds().length); + + Thread.sleep(3000L); + Assert.assertEquals(1, valve.getStuckThreadIds().length); + } finally { + asyncThread.join(); + } Assert.assertFalse(stuckingServlet.wasInterrupted); Assert.assertTrue(result.toString().startsWith("OK")); } @@ -101,7 +102,7 @@ public class TestStuckThreadDetectionVal StuckThreadDetectionValve valve = new StuckThreadDetectionValve(); valve.setThreshold(2); - valve.setInterruptThreadThreshold(4); + valve.setInterruptThreadThreshold(5); context.addValve(valve); context.setBackgroundProcessorDelay(1); tomcat.start(); @@ -122,18 +123,16 @@ public class TestStuckThreadDetectionVal }; asyncThread.start(); - - Thread.sleep(1000L); - Assert.assertEquals(0, valve.getStuckThreadIds().length); - - Thread.sleep(3000L); - Assert.assertEquals(1, valve.getStuckThreadIds().length); - - Thread.sleep(3000L); - Assert.assertTrue(stuckingServlet.wasInterrupted); - Assert.assertEquals(0, valve.getStuckThreadIds().length); - - asyncThread.join(); + try { + Thread.sleep(4000L); + Assert.assertEquals(1, valve.getStuckThreadIds().length); + + Thread.sleep(4000L); + Assert.assertTrue(stuckingServlet.wasInterrupted); + Assert.assertEquals(0, valve.getStuckThreadIds().length); + } finally { + asyncThread.join(); + } Assert.assertTrue(result.toString().startsWith("OK")); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org