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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun May 15 14:34:45 UTC 2016


 loolwsd/test/httpwstest.cpp |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

New commits:
commit 1eb239ee671233dcd2c276561f7b716a35d4d363
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun May 15 10:23:18 2016 -0400

    loolwsd: better editlock test
    
    Change-Id: Ia0fa59b3b6b61bd054bd3d25f126884f4e5211b7
    Reviewed-on: https://gerrit.libreoffice.org/25008
    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 2515ed0..94e04b4 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -919,6 +919,10 @@ void HTTPWSTest::testEditLock()
     const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
     const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
 
+    // This test doesn't really need to be multithreaded.
+    // But it's done this way as an experiment and to serve
+    // as an example for other similar tests (where necessary).
+    // Ultimately, the complexity doesn't justify it.
     std::mutex mutex;
     std::condition_variable cv;
     volatile bool second_client_died = false;
@@ -951,7 +955,7 @@ void HTTPWSTest::testEditLock()
                                     lock.unlock();
                                     cv.notify_one();
                                 }
-                                else if (editlock1 == "editlock: 1")
+                                else if (msg == "editlock: 1")
                                 {
                                     if (second_client_died)
                                     {
@@ -966,6 +970,7 @@ void HTTPWSTest::testEditLock()
                                     {
                                         // Normal broadcast when the second client joins.
                                         std::cerr << "First client still has the lock." << std::endl;
+                                        CPPUNIT_ASSERT_EQUAL(std::string("editlock: 1"), msg);
                                         CPPUNIT_ASSERT_MESSAGE("First doesn't have the lock", first_has_editlock);
                                     }
                                 }
@@ -975,6 +980,8 @@ void HTTPWSTest::testEditLock()
                                     std::cerr << "First client lost the lock." << std::endl;
                                     CPPUNIT_ASSERT_EQUAL(std::string("editlock: 0"), msg);
                                     first_has_editlock = false;
+                                    std::cerr << "Allowing the second to die." << std::endl;
+                                    cv.notify_one();
                                 }
                             }
 
@@ -1015,6 +1022,9 @@ void HTTPWSTest::testEditLock()
                             // But we will take it.
                             std::cerr << "Second client taking lock." << std::endl;
                             sendTextFrame(*socket, "takeedit");
+
+                            // Wait until the first gets the notification that we took it.
+                            cv.wait(lock);
                         }
                         else
                         {
@@ -1030,8 +1040,8 @@ void HTTPWSTest::testEditLock()
                 });
 
         std::cerr << "Second client out." << std::endl;
-        socket->shutdown();
         second_client_died = true;
+        socket->shutdown();
         first_client.join();
 
         // The second will think it had the lock when it died, but it will give it up.


More information about the Libreoffice-commits mailing list