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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Fri May 13 12:58:58 UTC 2016


 loolwsd/test/httpwstest.cpp |   19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

New commits:
commit 3cf2810ac2f5e47d96f05133dd545fb514b68aa0
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Fri May 13 08:47:47 2016 -0400

    loolwsd: improved testEditLock to minimize random failures and maximize checks
    
    Change-Id: I8ae03d57c9f0f13ebf75122dc66ccdf5b756917d
    Reviewed-on: https://gerrit.libreoffice.org/24969
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index dc7f000..6c9a658 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -1019,6 +1019,8 @@ void HTTPWSTest::testEditLock()
     std::mutex mutex;
     std::condition_variable cv;
     volatile bool second_client_died = false;
+    volatile bool first_has_editlock = false;
+    volatile bool second_has_editlock = false;
 
     // The first client loads the document and checks that it has the lock.
     // It then waits until the lock is taken away.
@@ -1029,8 +1031,8 @@ void HTTPWSTest::testEditLock()
                 std::cerr << "First client loading." << std::endl;
                 auto socket = loadDocAndGetSocket(_uri, documentURL, "editLock-1 ", true);
                 std::string editlock1;
-                sendTextFrame(socket, "status");
-                SocketProcessor("First", socket, [&](const std::string& msg)
+                std::unique_lock<std::mutex> lock(mutex);
+                SocketProcessor("First ", socket, [&](const std::string& msg)
                         {
                             if (msg.find("editlock") == 0)
                             {
@@ -1038,10 +1040,12 @@ void HTTPWSTest::testEditLock()
                                 {
                                     std::cerr << "First client has the lock." << std::endl;
                                     CPPUNIT_ASSERT_EQUAL(std::string("editlock: 1"), msg);
+                                    first_has_editlock = true;
                                     editlock1 = msg;
 
                                     // Initial condition met, connect second client.
                                     std::cerr << "Starting second client." << std::endl;
+                                    lock.unlock();
                                     cv.notify_one();
                                 }
                                 else if (editlock1 == "editlock: 1")
@@ -1052,12 +1056,14 @@ void HTTPWSTest::testEditLock()
                                         // but we should get it back once they die.
                                         std::cerr << "First client is given the lock." << std::endl;
                                         CPPUNIT_ASSERT_EQUAL(std::string("editlock: 1"), msg);
+                                        first_has_editlock = true;
                                         return false; // Done!
                                     }
                                     else
                                     {
                                         // Normal broadcast when the second client joins.
                                         std::cerr << "First client still has the lock." << std::endl;
+                                        CPPUNIT_ASSERT_MESSAGE("First doesn't have the lock", first_has_editlock);
                                     }
                                 }
                                 else
@@ -1065,6 +1071,7 @@ void HTTPWSTest::testEditLock()
                                     // Another client took the lock.
                                     std::cerr << "First client lost the lock." << std::endl;
                                     CPPUNIT_ASSERT_EQUAL(std::string("editlock: 0"), msg);
+                                    first_has_editlock = false;
                                 }
                             }
 
@@ -1099,6 +1106,7 @@ void HTTPWSTest::testEditLock()
                             // We shouldn't have it.
                             std::cerr << "Second client doesn't have the lock." << std::endl;
                             CPPUNIT_ASSERT_EQUAL(std::string("editlock: 0"), msg);
+                            second_has_editlock = false;
                             editlock1 = msg;
 
                             // But we will take it.
@@ -1110,6 +1118,7 @@ void HTTPWSTest::testEditLock()
                             // Now it should be ours.
                             std::cerr << "Second client took the lock." << std::endl;
                             CPPUNIT_ASSERT_EQUAL(std::string("editlock: 1"), msg);
+                            second_has_editlock = true;
                             return false;
                         }
                     }
@@ -1120,8 +1129,12 @@ void HTTPWSTest::testEditLock()
         std::cerr << "Second client out." << std::endl;
         socket->shutdown();
         second_client_died = true;
-
         first_client.join();
+
+        // The second will think it had the lock when it died, but it will give it up.
+        CPPUNIT_ASSERT_MESSAGE("Second doesn't have the lock", second_has_editlock);
+        // The first must ultimately have the lock back.
+        CPPUNIT_ASSERT_MESSAGE("First didn't get back the lock", first_has_editlock);
     }
     catch (const Poco::Exception& exc)
     {


More information about the Libreoffice-commits mailing list