loolwsd/test/httpcrashtest.cpp | 84 ++++++++++++++++++----------------------- loolwsd/test/httpwstest.cpp | 20 +++++---- 2 files changed, 49 insertions(+), 55 deletions(-)
New commits: commit f3e5fb7d54bbd2da8b6cf5cbb4c5507280fe7deb Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Thu May 12 10:59:00 2016 -0400 loolwsd: better crash tests [tml says: Now (2016-10-11) 'make check' passes here in this (collabora-online-1-0) branch. Please don't break it.] Change-Id: I41d6ae0c80d842ffb3a67f6e20376c0b10068ea5 Reviewed-on: https://gerrit.libreoffice.org/24936 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/test/httpcrashtest.cpp b/loolwsd/test/httpcrashtest.cpp index ce71d66..0ead7ee 100644 --- a/loolwsd/test/httpcrashtest.cpp +++ b/loolwsd/test/httpcrashtest.cpp @@ -56,15 +56,9 @@ class HTTPCrashTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE(HTTPCrashTest); - // This should be the first test: - CPPUNIT_TEST(testCountHowManyLoolkits); - CPPUNIT_TEST(testBarren); CPPUNIT_TEST(testCrashKit); - // This should be the last test: - CPPUNIT_TEST(testNoExtraLoolKitsLeft); - CPPUNIT_TEST_SUITE_END(); void testCountHowManyLoolkits(); @@ -98,10 +92,12 @@ public: void setUp() { + testCountHowManyLoolkits(); } void tearDown() { + testNoExtraLoolKitsLeft(); } }; @@ -127,45 +123,38 @@ void HTTPCrashTest::testBarren() { killLoKitProcesses(); + std::cerr << "Loading after kill." << std::endl; + // Load a document and get its status. - const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt"); - const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); + std::string documentPath, documentURL; + getDocumentPathAndURL("hello.odt", documentPath, documentURL); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); - Poco::Net::WebSocket socket = *connectLOKit(_uri, request, _response); + auto socket = connectLOKit(_uri, request, _response); + // First load should fail. sendTextFrame(socket, "load url=" + documentURL); - sendTextFrame(socket, "status"); - CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket)); - - // 5 seconds timeout - socket.setReceiveTimeout(5000000); - - std::string status; - int flags; - int n; - do - { - char buffer[READ_BUFFER_SIZE]; - n = socket.receiveFrame(buffer, sizeof(buffer), flags); - std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << std::endl; - if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) - { - std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << std::endl; - const std::string line = LOOLProtocol::getFirstLine(buffer, n); - const std::string prefix = "status: "; - if (line.find(prefix) == 0) + SocketProcessor("Barren", socket, [&](const std::string& msg) { - status = line.substr(prefix.length()); - // Might be too strict, consider something flexible instread. - CPPUNIT_ASSERT_EQUAL(std::string("type=text parts=1 current=0 width=12808 height=16408"), status); - break; - } - } - } - while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE); + const std::string prefix = "status: "; + if (msg.find(prefix) == 0) + { + const auto status = msg.substr(prefix.length()); + CPPUNIT_ASSERT_EQUAL(std::string("type=text parts=1 current=0 width=12808 height=16408"), status); + return false; + } + else if (msg.find("Service") == 0) + { + // Service unavailable. Try again. + auto socket2 = loadDocAndGetSocket(_uri, documentURL); + sendTextFrame(socket2, "status"); + const auto status = getResponseLine(socket2, "status"); + CPPUNIT_ASSERT_EQUAL(std::string("type=text parts=1 current=0 width=12808 height=16408"), status); + return false; + } - socket.shutdown(); + return true; + }); } catch (const Poco::Exception& exc) { @@ -177,27 +166,27 @@ void HTTPCrashTest::testCrashKit() { try { - int bytes; - int flags; - char buffer[READ_BUFFER_SIZE]; - // Load a document and get its status. - const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt"); - const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); + std::string documentPath, documentURL; + getDocumentPathAndURL("hello.odt", documentPath, documentURL); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); - Poco::Net::WebSocket socket = *connectLOKit(_uri, request, _response); + auto socket = *connectLOKit(_uri, request, _response); sendTextFrame(socket, "load url=" + documentURL); - sendTextFrame(socket, "status"); CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket)); killLoKitProcesses(); + std::cerr << "Reading after kill." << std::endl; + // 5 seconds timeout socket.setReceiveTimeout(5000000); // receive close frame handshake + int bytes; + int flags; + char buffer[READ_BUFFER_SIZE]; do { bytes = socket.receiveFrame(buffer, sizeof(buffer), flags); @@ -244,6 +233,7 @@ void HTTPCrashTest::killLoKitProcesses() Poco::StringTokenizer tokens(statString, " "); if (tokens.count() > 3 && tokens[1] == "(loolkit)") { + std::cerr << "Killing " << pid << std::endl; if (kill(pid, SIGKILL) == -1) { std::cerr << "kill(" << pid << ",SIGKILL) failed: " << std::strerror(errno) << std::endl; @@ -255,6 +245,8 @@ void HTTPCrashTest::killLoKitProcesses() { } } + + countLoolKitProcesses(0); } CPPUNIT_TEST_SUITE_REGISTRATION(HTTPCrashTest); diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp index 32d04dd..a1b464b 100644 --- a/loolwsd/test/httpwstest.cpp +++ b/loolwsd/test/httpwstest.cpp @@ -231,6 +231,7 @@ void HTTPWSTest::testHandShake() std::string documentPath, documentURL; getDocumentPathAndURL("hello.odt", documentPath, documentURL); + // NOTE: Do not replace with wrappers. This has to be explicit. Poco::Net::HTTPResponse response; Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri)); commit a90526322c0895489a6e95b09750c71d789a3707 Author: Tor Lillqvist <t...@collabora.com> Date: Tue Oct 11 16:21:47 2016 +0300 Accept also 'graphicselection:' Also, sort the lines for sanity. diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp index c7c3c09..32d04dd 100644 --- a/loolwsd/test/httpwstest.cpp +++ b/loolwsd/test/httpwstest.cpp @@ -1265,15 +1265,16 @@ void HTTPWSTest::testInactiveClient() { const auto token = LOOLProtocol::getFirstToken(msg); CPPUNIT_ASSERT_MESSAGE("unexpected message: " + msg, - token == "setpart:" || - token == "textselection:" || - token == "textselectionstart:" || - token == "textselectionend:" || - token == "invalidatetiles:" || - token == "invalidatecursor:" || - token == "statechanged:" || - token == "viewinfo:" || - token == "editlock:"); + token == "editlock:" || + token == "graphicselection:" || + token == "invalidatecursor:" || + token == "invalidatetiles:" || + token == "setpart:" || + token == "statechanged:" || + token == "textselection:" || + token == "textselectionend:" || + token == "textselectionstart:" || + token == "viewinfo:"); // End when we get state changed. return (token != "statechanged:"); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits