tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1173020 - /tomcat/trunk/test/org/apache/catalina/comet/TestCometProcessor.java
Date Tue, 20 Sep 2011 08:33:44 GMT
Author: markt
Date: Tue Sep 20 08:33:44 2011
New Revision: 1173020

URL: http://svn.apache.org/viewvc?rev=1173020&view=rev
Log:
Better detection of thread termination at end of test
Better failure messages so it is easier to see the cause of any failure immediately 

Modified:
    tomcat/trunk/test/org/apache/catalina/comet/TestCometProcessor.java

Modified: tomcat/trunk/test/org/apache/catalina/comet/TestCometProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/comet/TestCometProcessor.java?rev=1173020&r1=1173019&r2=1173020&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/comet/TestCometProcessor.java (original)
+++ tomcat/trunk/test/org/apache/catalina/comet/TestCometProcessor.java Tue Sep 20 08:33:44
2011
@@ -154,14 +154,27 @@ public class TestCometProcessor extends 
         tomcat.getConnector().stop();
         tomcat.getConnector().destroy();
 
-        // Sleep for a couple of seconds to give enough time for the connector
-        // stop message to be processed
-        Thread.sleep(2000);
+        // Wait for the write thread to stop
+        int count = 0;
+        while (writeThread.isAlive() && count < 100) {
+            Thread.sleep(100);
+            count ++;
+        }
+
+        // Wait for the read thread to stop
+        count = 0;
+        while (readThread.isAlive() && count < 100) {
+            Thread.sleep(100);
+            count ++;
+        }
 
         // Write should trigger an exception once the connector stops since the
         // socket should be closed
-        assertNotNull(writeThread.getException());
-        assertNull(readThread.getException());
+        assertNotNull("No exception in writing thread",
+                writeThread.getException());
+        // Read should terminate gracefully with an EOF
+        assertNull("Read thread terminated with an exception",
+                readThread.getException());
     }
 
     private boolean isCometSupported() {
@@ -217,7 +230,7 @@ public class TestCometProcessor extends 
         
         private int pingCount;
         private OutputStream os;
-        private Exception e = null;
+        private volatile Exception e = null;
 
         public PingWriterThread(int pingCount, OutputStream os) {
             this.pingCount = pingCount;
@@ -271,6 +284,7 @@ public class TestCometProcessor extends 
                     response.append((char) c);
                     c = is.read();
                 }
+                System.out.println("EOF");
             } catch (Exception e) {
                 this.e = e;
             }



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


Mime
View raw message