diff --git a/net/src/test/java/com/zfoo/net/core/json/client/JsonWebsocketClientTest.java b/net/src/test/java/com/zfoo/net/core/json/client/JsonWebsocketClientTest.java index 104f301e7..c81858b4b 100644 --- a/net/src/test/java/com/zfoo/net/core/json/client/JsonWebsocketClientTest.java +++ b/net/src/test/java/com/zfoo/net/core/json/client/JsonWebsocketClientTest.java @@ -48,7 +48,7 @@ public void startClient() throws Exception { var client = new JsonWebsocketClient(HostAndPort.valueOf("127.0.0.1:9000"), webSocketClientProtocolConfig); var session = client.start(); - // Websocket在建立tcp连接过后不能立刻通讯,还需要使用Http协议去握手升级成Websocket协议 + // Websocket在建立tcp连接过后不能立刻通讯,还需要使用Http协议去握手升级成Websocket协议,这里等待一秒让websocket内部协议初始化完毕 // WebSocket握手是在客户端和服务器之间建立WebSocket连接的过程。它是通过HTTP/HTTPS协议完成的,后续将升级为WebSocket协议。 ThreadUtils.sleep(1000); @@ -58,7 +58,6 @@ public void startClient() throws Exception { for (int i = 0; i < 1000; i++) { NetContext.getRouter().send(session, request); - ThreadUtils.sleep(1000); var response = NetContext.getRouter().syncAsk(session, request, JsonHelloResponse.class, null).packet(); logger.info("sync json client receive [packet:{}] from server", JsonUtils.object2String(response)); @@ -69,6 +68,7 @@ public void accept(JsonHelloResponse jsonHelloResponse) { logger.info("async json client receive [packet:{}] from server", JsonUtils.object2String(jsonHelloResponse)); } }); + ThreadUtils.sleep(1000); } ThreadUtils.sleep(Long.MAX_VALUE); diff --git a/net/src/test/java/com/zfoo/net/core/websocket/client/WebsocketClientTest.java b/net/src/test/java/com/zfoo/net/core/websocket/client/WebsocketClientTest.java index c4017d8b8..ee3525a25 100644 --- a/net/src/test/java/com/zfoo/net/core/websocket/client/WebsocketClientTest.java +++ b/net/src/test/java/com/zfoo/net/core/websocket/client/WebsocketClientTest.java @@ -48,7 +48,7 @@ public void startClient() throws Exception { var client = new WebsocketClient(HostAndPort.valueOf("127.0.0.1:9000"), webSocketClientProtocolConfig); var session = client.start(); - // Websocket在建立tcp连接过后不能立刻通讯,还需要使用Http协议去握手升级成Websocket协议 + // Websocket在建立tcp连接过后不能立刻通讯,还需要使用Http协议去握手升级成Websocket协议,这里等待一秒让websocket内部协议初始化完毕 // WebSocket握手是在客户端和服务器之间建立WebSocket连接的过程。它是通过HTTP/HTTPS协议完成的,后续将升级为WebSocket协议。 ThreadUtils.sleep(1000); @@ -58,7 +58,6 @@ public void startClient() throws Exception { for (int i = 0; i < 1000; i++) { NetContext.getRouter().send(session, request); - ThreadUtils.sleep(1000); var response = NetContext.getRouter().syncAsk(session, request, WebsocketHelloResponse.class, null).packet(); logger.info("sync client receive [packet:{}] from server", JsonUtils.object2String(response)); @@ -69,6 +68,7 @@ public void accept(WebsocketHelloResponse jsonHelloResponse) { logger.info("async client receive [packet:{}] from server", JsonUtils.object2String(jsonHelloResponse)); } }); + ThreadUtils.sleep(1000); } ThreadUtils.sleep(Long.MAX_VALUE);