Fix unreliable test
Refactor test so each test uses a dedicated Listener instance
diff --git a/test/org/apache/coyote/http2/TestAsyncError.java b/test/org/apache/coyote/http2/TestAsyncError.java
index acfbecb..813a489 100644
--- a/test/org/apache/coyote/http2/TestAsyncError.java
+++ b/test/org/apache/coyote/http2/TestAsyncError.java
@@ -50,10 +50,12 @@
Tomcat tomcat = getTomcatInstance();
+ AsyncErrorServlet asyncErrorServlet = new AsyncErrorServlet();
+
Context ctxt = getProgrammaticRootContext();
Tomcat.addServlet(ctxt, "simple", new SimpleServlet());
ctxt.addServletMappingDecoded("/simple", "simple");
- Wrapper w = Tomcat.addServlet(ctxt, "async", new AsyncErrorServlet());
+ Wrapper w = Tomcat.addServlet(ctxt, "async", asyncErrorServlet);
w.setAsyncSupported(true);
ctxt.addServletMappingDecoded("/async", "async");
tomcat.start();
@@ -82,12 +84,12 @@
sendRst(3, Http2Error.CANCEL.getCode());
int count = 0;
- while (count < 50 && TestListener.getErrorCount() == 0) {
+ while (count < 50 && asyncErrorServlet.getErrorCount() == 0) {
count++;
Thread.sleep(100);
}
- Assert.assertEquals(1, TestListener.getErrorCount());
+ Assert.assertEquals(1, asyncErrorServlet.getErrorCount());
}
@@ -95,11 +97,16 @@
private static final long serialVersionUID = 1L;
+ private TestListener testListener = new TestListener();
+
+ int getErrorCount() {
+ return testListener.getErrorCount();
+ }
+
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final AsyncContext asyncContext = req.startAsync();
- TestListener testListener = new TestListener();
asyncContext.addListener(testListener);
MessageGenerator msgGenerator = new MessageGenerator(resp);
@@ -140,9 +147,9 @@
private static final class TestListener implements AsyncListener {
- private static final AtomicInteger errorCount = new AtomicInteger(0);
+ private final AtomicInteger errorCount = new AtomicInteger(0);
- public static int getErrorCount() {
+ public int getErrorCount() {
return errorCount.get();
}