[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-1-0' - loolwsd/test
Pranav Kant
pranavk at collabora.co.uk
Mon Jul 18 09:22:55 UTC 2016
loolwsd/test/UnitAdmin.cpp | 68 +++++++++++++++++++--------------------------
1 file changed, 30 insertions(+), 38 deletions(-)
New commits:
commit 1f64268255d2ac5eea36845c3aaca32b91a53e00
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
(cherry picked from commit 4530bfdb0a8b86285bc97bc7e849d5c1e26aef22)
diff --git a/loolwsd/test/UnitAdmin.cpp b/loolwsd/test/UnitAdmin.cpp
index 7ba4ffe..2ae8520 100644
--- a/loolwsd/test/UnitAdmin.cpp
+++ b/loolwsd/test/UnitAdmin.cpp
@@ -199,22 +199,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" ||
@@ -230,22 +227,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" ||
@@ -268,21 +262,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