Skip to content

Commit

Permalink
Refactor test to make it more robust.
Browse files Browse the repository at this point in the history
The test was failing for NIO2 after changes to
TesterFirehoseServer.SEND_TIME_OUT_MILLIS. This fixes that failure and
makes the test more robust for any future changes.
  • Loading branch information
markt-asf committed Feb 4, 2025
1 parent a707654 commit 95716c6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions test/org/apache/tomcat/websocket/server/TestSlowClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,24 @@ public void testSendingFromAppThread() throws Exception {
// Trigger the sending of the messages from the server
wsSession.getBasicRemote().sendText("start");

// Wait for server to close connection (it shouldn't)
// 20s should be long enough even for the slowest CI system. May need to
// extend this if not.
/*
* Wait for server to experience a write timeout. This should take TesterFirehoseServer.SEND_TIME_OUT_MILLIS
* plus however long it takes for the network buffer to fill up which should be a few milliseconds. An
* additional 10s should be enough even for the slowest CI system.
*
* As soon as the server has experienced the write timeout, send the session close message from the client and
* close the network connection.
*/
Thread.sleep(TesterFirehoseServer.SEND_TIME_OUT_MILLIS);
int count = 0;
while (wsSession.isOpen() && count < 200) {
Thread.sleep(100);
while (wsSession.isOpen() && TesterFirehoseServer.Endpoint.getErrorCount() == 0 && count < 200) {
Thread.sleep(50);
count++;
}
Assert.assertTrue(TesterFirehoseServer.Endpoint.getErrorCount() > 0);
Assert.assertTrue(wsSession.isOpen());

// Cast so we can force the session to be closed quickly.
// Cast so we can force the session and the socket to be closed quickly.
CloseReason cr = new CloseReason(CloseCodes.CLOSED_ABNORMALLY, "");
((WsSession) wsSession).doClose(cr, cr, true);

Expand Down

0 comments on commit 95716c6

Please sign in to comment.