[Libreoffice-commits] online.git: 2 commits - loolwsd/test

Pranav Kant pranavk at collabora.co.uk
Wed Jul 13 19:41:31 UTC 2016


 loolwsd/test/UnitAdmin.cpp |   92 +++++++++++++++++++--------------------------
 1 file changed, 39 insertions(+), 53 deletions(-)

New commits:
commit 0f506fcbb0d17a58727b75ebf6b359a3926abc39
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Jul 14 01:07:00 2016 +0530

    Some more admin test cleaning
    
    Change-Id: I3cea5b6fefcb7b4e6209c63e6b3e232b9db50a7b

diff --git a/loolwsd/test/UnitAdmin.cpp b/loolwsd/test/UnitAdmin.cpp
index 97e1cc4..edd6bb1 100644
--- a/loolwsd/test/UnitAdmin.cpp
+++ b/loolwsd/test/UnitAdmin.cpp
@@ -295,14 +295,12 @@ private:
 
     TestResult testUsersCount()
     {
-        _messageReceived.clear();
-
         const std::string queryMessage = "active_users_count";
-        _adminWs->sendFrame(queryMessage.data(), queryMessage.size());
+        _messageReceived.clear();
 
         std::unique_lock<std::mutex> lock(_messageReceivedMutex);
-        if (_messageReceived.empty() &&
-            _messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout)
+        _adminWs->sendFrame(queryMessage.data(), queryMessage.size());
+        if (_messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout)
         {
             Log::info("testUsersCount: Timed out waiting for admin console message");
             return TestResult::TEST_TIMED_OUT;
@@ -330,14 +328,12 @@ private:
 
     TestResult testDocCount()
     {
-        _messageReceived.clear();
-
         const std::string queryMessage = "active_docs_count";
-        _adminWs->sendFrame(queryMessage.data(), queryMessage.size());
+        _messageReceived.clear();
 
         std::unique_lock<std::mutex> lock(_messageReceivedMutex);
-        if (_messageReceived.empty() &&
-            _messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout)
+        _adminWs->sendFrame(queryMessage.data(), queryMessage.size());
+        if (_messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout)
         {
             Log::info("testDocCount: Timed out waiting for admin console message");
             return TestResult::TEST_TIMED_OUT;
@@ -366,16 +362,14 @@ private:
 
     TestResult testRmDocNotify()
     {
-        _messageReceived.clear();
-
         // subscribe to rmdoc notification on admin websocket
         const std::string subscribeMessage = "subscribe rmdoc";
         _adminWs->sendFrame(subscribeMessage.data(), subscribeMessage.size());
+        _messageReceived.clear();
 
-        _docWs1->close();
         std::unique_lock<std::mutex> lock(_messageReceivedMutex);
-        if (_messageReceived.empty() &&
-            _messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout)
+        _docWs1->close();
+        if (_messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout)
         {
             Log::info("testRmDocNotify: Timed out waiting for admin console message");
             return TestResult::TEST_TIMED_OUT;
commit 4530bfdb0a8b86285bc97bc7e849d5c1e26aef22
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Jul 14 00:46:16 2016 +0530

    loolwsd: Fix Admin unit test
    
    Admin notify messages are emitted when websocket connection is
    established, not when 'load' message is sent.
    
    And, some minor cleaning.
    
    Change-Id: If52a77c10c3af64dcca8d6c10868b3d46f48c774

diff --git a/loolwsd/test/UnitAdmin.cpp b/loolwsd/test/UnitAdmin.cpp
index 6bfe261..97e1cc4 100644
--- a/loolwsd/test/UnitAdmin.cpp
+++ b/loolwsd/test/UnitAdmin.cpp
@@ -198,22 +198,19 @@ private:
         const std::string loadMessage1 = "load url=" + documentURL1;
         std::unique_ptr<HTTPClientSession> session1(helpers::createSession(docUri1));
         std::unique_ptr<HTTPClientSession> session2(helpers::createSession(docUri1));
-        _docWs1 = std::make_shared<Poco::Net::WebSocket>(*session1, request1, response1);
-        _docWs2 = std::make_shared<Poco::Net::WebSocket>(*session2, request1, response1);
 
+        std::unique_lock<std::mutex> lock(_messageReceivedMutex);
+        _messageReceived.clear();
+        _docWs1 = std::make_shared<Poco::Net::WebSocket>(*session1, request1, response1);
+        _docWs1->sendFrame(loadMessage1.data(), loadMessage1.size());
+        if (_messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout)
         {
-            _messageReceived.clear();
-            _docWs1->sendFrame(loadMessage1.data(), loadMessage1.size());
-
-            std::unique_lock<std::mutex> lock(_messageReceivedMutex);
-            if (_messageReceived.empty() &&
-                _messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout)
-            {
-                Log::info("testAddDocNotify: Timed out waiting for admin console message");
-                return TestResult::TEST_TIMED_OUT;
-            }
-            lock.unlock();
+            Log::info("testAddDocNotify: Timed out waiting for admin console message");
+            return TestResult::TEST_TIMED_OUT;
+        }
+        lock.unlock();
 
+        {
             StringTokenizer tokens(_messageReceived, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
             if (tokens.count() != 5 ||
                 tokens[0] != "adddoc" ||
@@ -229,22 +226,19 @@ private:
         }
         _docsCount++;
 
-
         // Open another view of same document
+        lock.lock(); // lock _messageReceivedMutex
+        _messageReceived.clear();
+        _docWs2 = std::make_shared<Poco::Net::WebSocket>(*session2, request1, response1);
+        _docWs2->sendFrame(loadMessage1.data(), loadMessage1.size());
+        if (_messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout)
         {
-            // Send another load request for same document
-            _messageReceived.clear();
-            _docWs2->sendFrame(loadMessage1.data(), loadMessage1.size());
-
-            std::unique_lock<std::mutex> lock(_messageReceivedMutex);
-            if (_messageReceived.empty() &&
-                _messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout)
-            {
-                Log::info("testAddDocNotify: Timed out waiting for admin console message");
-                return TestResult::TEST_TIMED_OUT;
-            }
-            lock.unlock();
+            Log::info("testAddDocNotify: Timed out waiting for admin console message");
+            return TestResult::TEST_TIMED_OUT;
+        }
+        lock.unlock();
 
+        {
             StringTokenizer tokens(_messageReceived, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
             if (tokens.count() != 5 ||
                 tokens[0] != "adddoc" ||
@@ -267,21 +261,19 @@ private:
         const Poco::URI docUri2(helpers::getTestServerURI());
         const std::string loadMessage2 = "load url=" + documentURL2;
         std::unique_ptr<HTTPClientSession> session3(helpers::createSession(docUri1));
-        _docWs3 = std::make_shared<Poco::Net::WebSocket>(*session3, request2, response2);
 
+        lock.lock(); // lock _messageReceivedMutex
+        _messageReceived.clear();
+        _docWs3 = std::make_shared<Poco::Net::WebSocket>(*session3, request2, response2);
+        _docWs3->sendFrame(loadMessage2.data(), loadMessage2.size());
+        if (_messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout)
         {
-            _messageReceived.clear();
-            _docWs3->sendFrame(loadMessage2.data(), loadMessage2.size());
-
-            std::unique_lock<std::mutex> lock(_messageReceivedMutex);
-            if (_messageReceived.empty() &&
-                _messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout)
-            {
-                Log::info("testAddDocNotify: Timed out waiting for admin console message");
-                return TestResult::TEST_TIMED_OUT;
-            }
-            lock.unlock();
+            Log::info("testAddDocNotify: Timed out waiting for admin console message");
+            return TestResult::TEST_TIMED_OUT;
+        }
+        lock.unlock();
 
+        {
             StringTokenizer tokens(_messageReceived, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
             if (tokens.count() != 5 ||
                 tokens[0] != "adddoc" ||


More information about the Libreoffice-commits mailing list