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/07/07 19:53:27 UTC
[tomcat] branch master updated: Make tests more robust. Fix
disabled tests.
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 45c03ee Make tests more robust. Fix disabled tests.
45c03ee is described below
commit 45c03ee391d39da3da123dccee7dfff85d413a3f
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Jul 7 20:52:40 2020 +0100
Make tests more robust. Fix disabled tests.
---
.../websocket/pojo/TestEncodingDecoding.java | 57 +++++++++++-----------
1 file changed, 29 insertions(+), 28 deletions(-)
diff --git a/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java b/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java
index ea7374d..ab1d7b1 100644
--- a/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java
+++ b/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java
@@ -49,7 +49,6 @@ import jakarta.websocket.server.ServerEndpoint;
import jakarta.websocket.server.ServerEndpointConfig;
import org.junit.Assert;
-import org.junit.Ignore;
import org.junit.Test;
import org.apache.catalina.Context;
@@ -70,6 +69,9 @@ public class TestEncodingDecoding extends TomcatBaseTest {
private static final String PATH_MESSAGES_EP = "/echoMessagesEP";
private static final String PATH_BATCHED_EP = "/echoBatchedEP";
+ private static final int WAIT_LOOPS = 50;
+ private static final int WAIT_DELAY = 100;
+
@Test
public void testProgrammaticEndPoints() throws Exception{
@@ -93,13 +95,13 @@ public class TestEncodingDecoding extends TomcatBaseTest {
session.getBasicRemote().sendObject(msg1);
// Should not take very long
int i = 0;
- while (i < 20) {
+ while (i < WAIT_LOOPS) {
if (MsgStringMessageHandler.received.size() > 0 &&
client.received.size() > 0) {
break;
}
i++;
- Thread.sleep(100);
+ Thread.sleep(WAIT_DELAY);
}
// Check messages were received
@@ -144,12 +146,12 @@ public class TestEncodingDecoding extends TomcatBaseTest {
// Should not take very long
int i = 0;
- while (i < 20) {
+ while (i < WAIT_LOOPS) {
if (server.received.size() > 0 && client.received.size() > 0) {
break;
}
i++;
- Thread.sleep(100);
+ Thread.sleep(WAIT_DELAY);
}
// Check messages were received
@@ -205,12 +207,12 @@ public class TestEncodingDecoding extends TomcatBaseTest {
// Should not take very long
int i = 0;
- while (i < 20) {
+ while (i < WAIT_LOOPS) {
if (server.received.size() > 0 && client.received.size() > 0) {
break;
}
i++;
- Thread.sleep(100);
+ Thread.sleep(WAIT_DELAY);
}
// Check messages were received
@@ -223,8 +225,8 @@ public class TestEncodingDecoding extends TomcatBaseTest {
session.close();
}
+
@Test
- @Ignore // TODO Investigate why this test fails
public void testMessagesEndPoints() throws Exception {
// Set up utility classes
MessagesServer server = new MessagesServer();
@@ -251,17 +253,17 @@ public class TestEncodingDecoding extends TomcatBaseTest {
// Should not take very long
int i = 0;
- while (i < 20) {
+ while (i < WAIT_LOOPS) {
if (server.received.size() > 0 && client.received.size() > 0) {
break;
}
i++;
- Thread.sleep(100);
+ Thread.sleep(WAIT_DELAY);
}
// Check messages were received
Assert.assertEquals(1, server.received.size());
- Assert.assertEquals(1, client.received.size());
+ Assert.assertEquals(2, client.received.size());
// Check correct messages were received
Assert.assertEquals(MESSAGE_ONE, server.received.peek());
@@ -272,7 +274,6 @@ public class TestEncodingDecoding extends TomcatBaseTest {
@Test
- @Ignore // TODO Investigate why this test fails
public void testBatchedEndPoints() throws Exception {
// Set up utility classes
BatchedServer server = new BatchedServer();
@@ -299,12 +300,12 @@ public class TestEncodingDecoding extends TomcatBaseTest {
// Should not take very long
int i = 0;
- while (i++ < 20) {
- if (server.received.size() > 0 && client.received.size() > 0) {
+ while (i++ < WAIT_LOOPS) {
+ if (server.received.size() > 0 && client.received.size() > 1) {
break;
}
i++;
- Thread.sleep(100);
+ Thread.sleep(WAIT_DELAY);
}
// Check messages were received
@@ -321,12 +322,12 @@ public class TestEncodingDecoding extends TomcatBaseTest {
private int testEvent(String name, int count) throws InterruptedException {
int i = count;
- while (i < 50) {
+ while (i < WAIT_LOOPS * 3) {
if (Server.isLifeCycleEventCalled(name)) {
break;
}
i++;
- Thread.sleep(100);
+ Thread.sleep(WAIT_DELAY);
}
Assert.assertTrue(Server.isLifeCycleEventCalled(name));
return i;
@@ -335,7 +336,7 @@ public class TestEncodingDecoding extends TomcatBaseTest {
@ClientEndpoint(decoders=ListStringDecoder.class, encoders=ListStringEncoder.class)
public static class GenericsClient {
- private Queue<Object> received = new ConcurrentLinkedQueue<>();
+ private final Queue<Object> received = new ConcurrentLinkedQueue<>();
@OnMessage
public void rx(List<String> in) {
@@ -348,7 +349,7 @@ public class TestEncodingDecoding extends TomcatBaseTest {
encoders={MsgStringEncoder.class, MsgByteEncoder.class})
public static class Client {
- private Queue<Object> received = new ConcurrentLinkedQueue<>();
+ private final Queue<Object> received = new ConcurrentLinkedQueue<>();
@OnMessage
public void rx(MsgString in) {
@@ -365,7 +366,7 @@ public class TestEncodingDecoding extends TomcatBaseTest {
@ClientEndpoint
public static class StringClient {
- private Queue<Object> received = new ConcurrentLinkedQueue<>();
+ private final Queue<Object> received = new ConcurrentLinkedQueue<>();
@OnMessage
public void rx(String in) {
@@ -381,8 +382,7 @@ public class TestEncodingDecoding extends TomcatBaseTest {
configurator=SingletonConfigurator.class)
public static class GenericsServer {
- private Queue<Object> received = new ConcurrentLinkedQueue<>();
-
+ private final Queue<Object> received = new ConcurrentLinkedQueue<>();
@OnMessage
public List<String> rx(List<String> in) {
@@ -401,9 +401,9 @@ public class TestEncodingDecoding extends TomcatBaseTest {
private volatile Throwable t = null;
@OnMessage
- public String onMessage(String message, Session session) {
+ public String onMessage(String message, Session session) throws Exception {
received.add(message);
- session.getAsyncRemote().sendText(MESSAGE_ONE);
+ session.getAsyncRemote().sendText(MESSAGE_ONE).get();
return message;
}
@@ -427,6 +427,7 @@ public class TestEncodingDecoding extends TomcatBaseTest {
received.add(message);
session.getAsyncRemote().setBatchingAllowed(true);
session.getAsyncRemote().sendText(MESSAGE_ONE);
+ session.getAsyncRemote().setBatchingAllowed(false);
return MESSAGE_TWO;
}
@@ -443,8 +444,8 @@ public class TestEncodingDecoding extends TomcatBaseTest {
configurator=SingletonConfigurator.class)
public static class Server {
- private Queue<Object> received = new ConcurrentLinkedQueue<>();
- static Map<String, Boolean> lifeCyclesCalled = new ConcurrentHashMap<>(8);
+ private final Queue<Object> received = new ConcurrentLinkedQueue<>();
+ static final Map<String, Boolean> lifeCyclesCalled = new ConcurrentHashMap<>(8);
@OnMessage
public MsgString rx(MsgString in) {
@@ -528,7 +529,7 @@ public class TestEncodingDecoding extends TomcatBaseTest {
public static class MsgString {
- private String data;
+ private volatile String data;
public String getData() { return data; }
public void setData(String data) { this.data = data; }
}
@@ -580,7 +581,7 @@ public class TestEncodingDecoding extends TomcatBaseTest {
public static class MsgByte {
- private byte[] data;
+ private volatile byte[] data;
public byte[] getData() { return data; }
public void setData(byte[] data) { this.data = data; }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org