You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/06/25 18:32:32 UTC

[tomcat] branch master updated: Fix various potential timing issues with this test.

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new 3f205cc  Fix various potential timing issues with this test.
3f205cc is described below

commit 3f205cc9d33c286ecf7a408685b41eeca3f6a58f
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jun 25 19:28:02 2020 +0100

    Fix various potential timing issues with this test.
    
    On the client side messages were sent via the async API in a loop. That
    creates a risk of breakage as it is not permitted to send the next
    message until the previous message completes and the client wasn't
    checking that the previous message had completed. SWitching to the basic
    API avoids this.
    
    On the server side, resume() was being called inside an async callback.
    It was possible for resume() to be called and one or more messages to be
    processed before the call to messages.clear(). Switching to the basic
    API allows the order to be controlled correctly.
---
 .../apache/tomcat/websocket/TestWsSessionSuspendResume.java  | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/test/org/apache/tomcat/websocket/TestWsSessionSuspendResume.java b/test/org/apache/tomcat/websocket/TestWsSessionSuspendResume.java
index cd2483e..b17dddf 100644
--- a/test/org/apache/tomcat/websocket/TestWsSessionSuspendResume.java
+++ b/test/org/apache/tomcat/websocket/TestWsSessionSuspendResume.java
@@ -69,7 +69,7 @@ public class TestWsSessionSuspendResume extends WebSocketBaseTest {
             latch.countDown();
         });
         for (int i = 0; i < 8; i++) {
-            wsSession.getAsyncRemote().sendText("echo");
+            wsSession.getBasicRemote().sendText("echo");
         }
 
         boolean latchResult = latch.await(30, TimeUnit.SECONDS);
@@ -131,11 +131,13 @@ public class TestWsSessionSuspendResume extends WebSocketBaseTest {
         void addMessage(String message) {
             if (messages.size() == count) {
                 ((WsSession) session).suspend();
-                session.getAsyncRemote().sendText(messages.toString(), result -> {
+                try {
+                    session.getBasicRemote().sendText(messages.toString());
+                    messages.clear();
                     ((WsSession) session).resume();
-                    Assert.assertTrue(result.isOK());
-                });
-                messages.clear();
+                } catch (IOException e) {
+                    Assert.fail();
+                }
             } else {
                 messages.add(message);
             }


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