From 606f85db8753e3d1f44b8fbf10be609e9bd5ccb7 Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Tue, 3 Jan 2017 17:02:53 -0500 Subject: [PATCH] wsd: fixup max connections unittest Change-Id: I107dadb973554b21f20211c8316cec7139953f47 Reviewed-on: https://gerrit.libreoffice.org/32713 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian --- test/helpers.hpp | 6 ++++++ test/httpwserror.cpp | 23 ++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/test/helpers.hpp b/test/helpers.hpp index 6c70fdd1e..4c9d19175 100644 --- a/test/helpers.hpp +++ b/test/helpers.hpp @@ -187,6 +187,12 @@ int getErrorCode(LOOLWebSocket& ws, std::string& message) return statusCode; } +inline +int getErrorCode(const std::shared_ptr& ws, std::string& message) +{ + return getErrorCode(*ws, message); +} + inline std::vector getResponseMessage(LOOLWebSocket& ws, const std::string& prefix, std::string name = "", const size_t timeoutMs = 10000) { diff --git a/test/httpwserror.cpp b/test/httpwserror.cpp index 3db733d01..c001abf04 100644 --- a/test/httpwserror.cpp +++ b/test/httpwserror.cpp @@ -142,8 +142,16 @@ void HTTPWSError::testMaxDocuments() void HTTPWSError::testMaxConnections() { -#if MAX_CONNECTIONS > 0 + static_assert(MAX_CONNECTIONS >= 3, "MAX_CONNECTIONS must be at least 3"); const auto testname = "maxConnections "; + + if (MAX_CONNECTIONS > 100) + { + std::cerr << "Skipping " << testname << "test since MAX_CONNECTION (" << MAX_CONNECTIONS + << ") is too high to test. Set to a more sensible number, ideally a dozen or so." << std::endl; + return; + } + try { std::cerr << "Opening max number of connections: " << MAX_CONNECTIONS << std::endl; @@ -158,7 +166,7 @@ void HTTPWSError::testMaxConnections() std::cerr << "Opened connect #1 of " << MAX_CONNECTIONS << std::endl; std::vector> views; - for(int it = 1; it < MAX_CONNECTIONS; it++) + for (int it = 1; it < MAX_CONNECTIONS; ++it) { std::unique_ptr session(createSession(_uri)); auto ws = std::make_shared(*session, request, _response); @@ -170,24 +178,21 @@ void HTTPWSError::testMaxConnections() // try to connect MAX_CONNECTIONS + 1 std::unique_ptr session(createSession(_uri)); - LOOLWebSocket socketN(*session, request, _response); + auto socketN = std::make_shared(*session, request, _response); - // send loolclient, load and partpagerectangles - sendTextFrame(socketN, "loolclient ", testname); - sendTextFrame(socketN, "load ", testname); - sendTextFrame(socketN, "partpagerectangles ", testname); + // Send load request, which will fail. + sendTextFrame(socketN, "load url=" + docURL, testname); std::string message; const auto statusCode = getErrorCode(socketN, message); CPPUNIT_ASSERT_EQUAL(static_cast(Poco::Net::WebSocket::WS_POLICY_VIOLATION), statusCode); - socketN.shutdown(); + socketN->shutdown(); } catch (const Poco::Exception& exc) { CPPUNIT_FAIL(exc.displayText()); } -#endif } CPPUNIT_TEST_SUITE_REGISTRATION(HTTPWSError);