Skip to content

Commit ea7ae89

Browse files
committed
Use regex comparison in WebSocket stats test
The output includes thread pool information which appears to not vary enough to cause failures locally but does so on the build server.
1 parent c18b6bf commit ea7ae89

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,16 @@ public void stompBrokerRelay() {
257257

258258
String name = "webSocketMessageBrokerStats";
259259
WebSocketMessageBrokerStats stats = this.appContext.getBean(name, WebSocketMessageBrokerStats.class);
260-
assertEquals("WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), " +
261-
"0 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], " +
262-
"stompSubProtocol[processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], " +
263-
"stompBrokerRelay[0 sessions, relayhost:1234 (not available), processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], " +
264-
"inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], " +
265-
"outboundChannelpool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], " +
266-
"sockJsScheduler[pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 0]",
267-
stats.toString());
260+
String actual = stats.toString();
261+
String expected = "WebSocketSession\\[0 current WS\\(0\\)-HttpStream\\(0\\)-HttpPoll\\(0\\), " +
262+
"0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)\\], " +
263+
"stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " +
264+
"stompBrokerRelay\\[0 sessions, relayhost:1234 \\(not available\\), processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " +
265+
"inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " +
266+
"outboundChannelpool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " +
267+
"sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\]";
268+
269+
assertTrue("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual, actual.matches(expected));
268270
}
269271

270272
@Test

spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
import java.util.Set;
2323
import java.util.concurrent.ScheduledThreadPoolExecutor;
2424

25+
import org.hamcrest.Description;
26+
import org.hamcrest.Matcher;
27+
import org.hamcrest.Matchers;
28+
import org.hamcrest.TypeSafeMatcher;
2529
import org.junit.Before;
2630
import org.junit.Test;
2731

@@ -138,14 +142,16 @@ public void messageBrokerSockJsTaskScheduler() {
138142
public void webSocketMessageBrokerStats() {
139143
String name = "webSocketMessageBrokerStats";
140144
WebSocketMessageBrokerStats stats = this.config.getBean(name, WebSocketMessageBrokerStats.class);
141-
assertEquals("WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), " +
142-
"0 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], " +
143-
"stompSubProtocol[processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], " +
144-
"stompBrokerRelay[null], " +
145-
"inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], " +
146-
"outboundChannelpool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], " +
147-
"sockJsScheduler[pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 0]",
148-
stats.toString());
145+
String actual = stats.toString();
146+
String expected = "WebSocketSession\\[0 current WS\\(0\\)-HttpStream\\(0\\)-HttpPoll\\(0\\), " +
147+
"0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)\\], " +
148+
"stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " +
149+
"stompBrokerRelay\\[null\\], " +
150+
"inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " +
151+
"outboundChannelpool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " +
152+
"sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\]";
153+
154+
assertTrue("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual, actual.matches(expected));
149155
}
150156

151157

0 commit comments

Comments
 (0)