This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new e9f25cdac7 Fix unreliable test
e9f25cdac7 is described below
commit e9f25cdac7fa98566b42b853f26d5a74a827a6af
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Sep 30 14:33:43 2025 +0100
Fix unreliable test
Refactor test so each test uses a dedicated Listener instance
---
test/org/apache/coyote/http2/TestAsyncError.java | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/test/org/apache/coyote/http2/TestAsyncError.java
b/test/org/apache/coyote/http2/TestAsyncError.java
index 41bc398f14..6cda72928e 100644
--- a/test/org/apache/coyote/http2/TestAsyncError.java
+++ b/test/org/apache/coyote/http2/TestAsyncError.java
@@ -49,10 +49,12 @@ public class TestAsyncError extends Http2TestBase {
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();
@@ -81,12 +83,12 @@ public class TestAsyncError extends Http2TestBase {
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());
}
@@ -94,11 +96,16 @@ public class TestAsyncError extends Http2TestBase {
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);
@@ -139,9 +146,9 @@ public class TestAsyncError extends Http2TestBase {
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();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]