[Libreoffice-commits] online.git: loolwsd/test
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Fri Sep 16 12:32:17 UTC 2016
loolwsd/test/helpers.hpp | 58 +++++++----------------------------------------
1 file changed, 9 insertions(+), 49 deletions(-)
New commits:
commit d2872846d83a848c5760afaa9bfc3d06fc3722f9
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Sep 11 14:29:09 2016 -0400
loolwsd: cleanup of unittests and helpers
Change-Id: I03a5cb29b51409f3b8cc51981b522248a29a6ba3
Reviewed-on: https://gerrit.libreoffice.org/28955
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/test/helpers.hpp b/loolwsd/test/helpers.hpp
index 4e60850..d6b519d 100644
--- a/loolwsd/test/helpers.hpp
+++ b/loolwsd/test/helpers.hpp
@@ -238,8 +238,9 @@ void getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std
}
inline
-std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, const std::string& name = "")
+std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std::string name = "")
{
+ name = name + '[' + prefix + "] ";
try
{
int flags = 0;
@@ -256,15 +257,16 @@ std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string
int bytes = ws.receiveFrame(response.data(), response.size(), flags);
response.resize(bytes >= 0 ? bytes : 0);
auto message = LOOLProtocol::getAbbreviatedMessage(response);
- std::cerr << name << "Got " << bytes << " bytes: " << message << std::endl;
if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
{
if (message.find(prefix) == 0)
{
+ std::cerr << name << "Got " << bytes << " bytes: " << message << std::endl;
return response;
}
else if (message.find("nextmessage") == 0)
{
+ std::cerr << name << "Got " << bytes << " bytes: " << message << std::endl;
Poco::StringTokenizer tokens(message, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
int size = 0;
if (tokens.count() == 2 &&
@@ -274,9 +276,9 @@ std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string
bytes = ws.receiveFrame(response.data(), response.size(), flags);
response.resize(bytes >= 0 ? bytes : 0);
message = LOOLProtocol::getAbbreviatedMessage(response);
- std::cerr << name << "Got " << bytes << " bytes: " << message << std::endl;
if (bytes > 0 && message.find(prefix) == 0)
{
+ std::cerr << name << "Got " << bytes << " bytes: " << message << std::endl;
return response;
}
}
@@ -293,11 +295,13 @@ std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string
{
break;
}
+
+ std::cerr << name << "Ignored: " << message << std::endl;
}
else
{
- std::cerr << name << "Timeout waiting for " << prefix << "\n";
--retries;
+ std::cerr << name << "Timeout " << retries << std::endl;
}
}
while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
@@ -467,51 +471,7 @@ void parseDocSize(const std::string& message, const std::string& type,
inline
std::vector<char> getTileMessage(Poco::Net::WebSocket& ws, const std::string& name = "")
{
- int flags = 0;
- int retries = 20;
- static const Poco::Timespan waitTime(1000000);
- std::vector<char> response(READ_BUFFER_SIZE);
-
- // 5 seconds timeout
- ws.setReceiveTimeout(5000000);
- do
- {
- if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ))
- {
- response.resize(READ_BUFFER_SIZE);
- int bytes = ws.receiveFrame(response.data(), response.size(), flags);
- response.resize(bytes >= 0 ? bytes : 0);
- auto message = LOOLProtocol::getAbbreviatedMessage(response);
- if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
- {
- if (message.find("nextmessage") == 0)
- {
- Poco::StringTokenizer tokens(message, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
- int size = 0;
- if (tokens.count() == 2 &&
- tokens[0] == "nextmessage:" && LOOLProtocol::getTokenInteger(tokens[1], "size", size) && size > 0)
- {
- std::cerr << name << " Got " << message << std::endl;
- response.resize(size);
- bytes = ws.receiveFrame(response.data(), response.size(), flags);
- response.resize(bytes >= 0 ? bytes : 0);
- return response;
- }
- }
- }
-
- std::cerr << name << "ignored " << message << std::endl;
- retries = 10;
- }
- else
- {
- std::cerr << name << "Timeout waiting for nextmessage:\n";
- --retries;
- }
- }
- while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
-
- return std::vector<char>();
+ return getResponseMessage(ws, "tile", name);
}
inline
More information about the Libreoffice-commits
mailing list