Author: markt
Date: Wed Dec 12 20:39:26 2018
New Revision: 1848795

URL: http://svn.apache.org/viewvc?rev=1848795&view=rev
Log:
I don't think this is the failure (I'd expect a subsequent thread not to see an 
update rather than to see too many updates) but fix it anyway.

Modified:
    tomcat/trunk/test/org/apache/coyote/http2/TestAsync.java

Modified: tomcat/trunk/test/org/apache/coyote/http2/TestAsync.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/TestAsync.java?rev=1848795&r1=1848794&r2=1848795&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http2/TestAsync.java (original)
+++ tomcat/trunk/test/org/apache/coyote/http2/TestAsync.java Wed Dec 12 
20:39:26 2018
@@ -25,6 +25,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.servlet.AsyncContext;
 import javax.servlet.ServletOutputStream;
@@ -232,7 +233,10 @@ public class TestAsync extends Http2Test
             final ServletOutputStream output = response.getOutputStream();
             output.setWriteListener(new WriteListener() {
 
-                int blockCount;
+                // Intermittent CI errors were observed where the response body
+                // was exactly one block too small. Use an AtomicInteger to be
+                // sure blockCount is thread-safe.
+                final AtomicInteger blockCount = new AtomicInteger(0);
                 byte[] bytes = new byte[BLOCK_SIZE];
 
 
@@ -258,9 +262,9 @@ public class TestAsync extends Http2Test
 
                 private void write() throws IOException {
                     while (output.isReady()) {
-                        blockCount++;
+                        blockCount.incrementAndGet();
                         output.write(bytes);
-                        if (blockCount == blockLimit) {
+                        if (blockCount.get()  == blockLimit) {
                             asyncContext.complete();
                             scheduler.shutdown();
                             return;



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

Reply via email to