From 6264a8b41d946e61bb30750ab1533c58f0cbc540 Mon Sep 17 00:00:00 2001 From: Kumamon38 Date: Tue, 21 May 2019 18:35:41 +0200 Subject: [PATCH] Fix ping (#80) * let poll do his job when closing * try fix test * try fix test * Update IXWebSocketTransport.cpp * add log to find issue on CI * add log to find issue on CI * add log to find issue on CI * add log to find issue on CI * add log to find issue on CI * change state immediately, and send close frame after * add immediate close test * disable test for windows * reenable ping / ping timeout tests * add time to let windows close client * reenable ping timeout test * add 100ms more * disable test for windows --- test/CMakeLists.txt | 4 ++-- test/IXWebSocketPingTest.cpp | 24 ++++++++++++------------ test/IXWebSocketPingTimeoutTest.cpp | 20 +++++++++----------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ba622404..6137811d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -45,12 +45,12 @@ if (UNIX) IXDNSLookupTest.cpp cmd_websocket_chat.cpp IXWebSocketCloseTest.cpp + IXWebSocketPingTest.cpp + IXWebSocketPingTimeoutTest.cpp ) endif() # Disable tests for now that are failing or not reliable -# IXWebSocketPingTest.cpp -# IXWebSocketPingTimeoutTest.cpp # IXWebSocketMessageQTest.cpp (trigger a segfault on Linux) add_executable(ixwebsocket_unittest ${SOURCES}) diff --git a/test/IXWebSocketPingTest.cpp b/test/IXWebSocketPingTest.cpp index cfcfabdd..4ddd2e2f 100644 --- a/test/IXWebSocketPingTest.cpp +++ b/test/IXWebSocketPingTest.cpp @@ -225,8 +225,8 @@ TEST_CASE("Websocket_ping_no_data_sent_setPingInterval", "[setPingInterval]") // -> expected ping messages == 2 as 2100 seconds, 1 ping sent every second REQUIRE(serverReceivedPingMessages == 2); - // Give us 500ms for the server to notice that clients went away - ix::msleep(500); + // Give us 1000ms for the server to notice that clients went away + ix::msleep(1000); REQUIRE(server.getClients().size() == 0); ix::reportWebSocketTraffic(); @@ -272,8 +272,8 @@ TEST_CASE("Websocket_ping_data_sent_setPingInterval", "[setPingInterval]") // -> expected ping messages == 3 as 900+900+1300 = 3100 seconds, 1 ping sent every second REQUIRE(serverReceivedPingMessages == 3); - // Give us 500ms for the server to notice that clients went away - ix::msleep(500); + // Give us 1000ms for the server to notice that clients went away + ix::msleep(1000); REQUIRE(server.getClients().size() == 0); ix::reportWebSocketTraffic(); @@ -325,8 +325,8 @@ TEST_CASE("Websocket_ping_data_sent_setPingInterval_half_full", "[setPingInterva webSocketClient.stop(); - // Give us 500ms for the server to notice that clients went away - ix::msleep(500); + // Give us 1000ms for the server to notice that clients went away + ix::msleep(1000); REQUIRE(server.getClients().size() == 0); ix::reportWebSocketTraffic(); @@ -377,8 +377,8 @@ TEST_CASE("Websocket_ping_data_sent_setPingInterval_full", "[setPingInterval]") webSocketClient.stop(); - // Give us 500ms for the server to notice that clients went away - ix::msleep(500); + // Give us 1000ms for the server to notice that clients went away + ix::msleep(1000); REQUIRE(server.getClients().size() == 0); ix::reportWebSocketTraffic(); @@ -422,8 +422,8 @@ TEST_CASE("Websocket_ping_no_data_sent_setHeartBeatPeriod", "[setHeartBeatPeriod // -> expected ping messages == 1 as 1900 seconds, 1 ping sent every second REQUIRE(serverReceivedPingMessages == 1); - // Give us 500ms for the server to notice that clients went away - ix::msleep(500); + // Give us 1000ms for the server to notice that clients went away + ix::msleep(1000); REQUIRE(server.getClients().size() == 0); ix::reportWebSocketTraffic(); @@ -472,8 +472,8 @@ TEST_CASE("Websocket_ping_data_sent_setHeartBeatPeriod", "[setHeartBeatPeriod]") // -> expected ping messages == 2 as 900+900+1100 = 2900 seconds, 1 ping sent every second REQUIRE(serverReceivedPingMessages == 2); - // Give us 500ms for the server to notice that clients went away - ix::msleep(500); + // Give us 1000ms for the server to notice that clients went away + ix::msleep(1000); REQUIRE(server.getClients().size() == 0); ix::reportWebSocketTraffic(); diff --git a/test/IXWebSocketPingTimeoutTest.cpp b/test/IXWebSocketPingTimeoutTest.cpp index 0b449427..2da16c91 100644 --- a/test/IXWebSocketPingTimeoutTest.cpp +++ b/test/IXWebSocketPingTimeoutTest.cpp @@ -259,8 +259,8 @@ TEST_CASE("Websocket_ping_timeout_not_checked", "[setPingTimeout]") webSocketClient.stop(); - // Give us 500ms for the server to notice that clients went away - ix::msleep(500); + // Give us 1000ms for the server to notice that clients went away + ix::msleep(1000); REQUIRE(server.getClients().size() == 0); // Ensure client close was not by ping timeout @@ -298,7 +298,7 @@ TEST_CASE("Websocket_ping_no_timeout", "[setPingTimeout]") REQUIRE(server.getClients().size() == 1); - ix::msleep(1100); + ix::msleep(1200); // Here we test ping timeout, no timeout REQUIRE(serverReceivedPingMessages == 1); @@ -312,8 +312,8 @@ TEST_CASE("Websocket_ping_no_timeout", "[setPingTimeout]") webSocketClient.stop(); - // Give us 500ms for the server to notice that clients went away - ix::msleep(500); + // Give us 1000ms for the server to notice that clients went away + ix::msleep(1000); REQUIRE(server.getClients().size() == 0); // Ensure client close was not by ping timeout @@ -365,7 +365,7 @@ TEST_CASE("Websocket_no_ping_but_timeout", "[setPingTimeout]") REQUIRE(serverReceivedPingMessages == 0); REQUIRE(webSocketClient.getReceivedPongMessages() == 0); // Ensure client close was by ping timeout - ix::msleep(300); + ix::msleep(1000); REQUIRE(webSocketClient.isClosed() == true); REQUIRE(webSocketClient.closedDueToPingTimeout() == true); @@ -417,7 +417,7 @@ TEST_CASE("Websocket_ping_timeout", "[setPingTimeout]") REQUIRE(serverReceivedPingMessages == 1); REQUIRE(webSocketClient.getReceivedPongMessages() == 0); // Ensure client close was by ping timeout - ix::msleep(300); + ix::msleep(1000); REQUIRE(webSocketClient.isClosed() == true); REQUIRE(webSocketClient.closedDueToPingTimeout() == true); @@ -429,7 +429,6 @@ TEST_CASE("Websocket_ping_timeout", "[setPingTimeout]") } } -#if 0 // this test fails on travis / commenting it out for now to get back to a green travis state TEST_CASE("Websocket_ping_long_timeout", "[setPingTimeout]") { SECTION("Make sure that ping messages don't have responses (no PONG).") @@ -458,7 +457,7 @@ TEST_CASE("Websocket_ping_long_timeout", "[setPingTimeout]") REQUIRE(server.getClients().size() == 1); - ix::msleep(5900); + ix::msleep(5800); // Here we test ping timeout, no timeout yet (2 ping sent at 2s and 4s) REQUIRE(serverReceivedPingMessages == 2); @@ -468,7 +467,7 @@ TEST_CASE("Websocket_ping_long_timeout", "[setPingTimeout]") REQUIRE(webSocketClient.isClosed() == false); REQUIRE(webSocketClient.closedDueToPingTimeout() == false); - ix::msleep(200); + ix::msleep(600); // Here we test ping timeout, timeout (at 6 seconds) REQUIRE(serverReceivedPingMessages == 2); @@ -484,4 +483,3 @@ TEST_CASE("Websocket_ping_long_timeout", "[setPingTimeout]") ix::reportWebSocketTraffic(); } } -#endif