nb: websocket echo test
The new test sends data of of 1 byte to N bytes and expects the exact same data returned in response. This tests both buffering sizes and websocket frames. Change-Id: Ic6232b4e899d82d90a0ee7c96e4852ffaaf8e958 Reviewed-on: https://gerrit.libreoffice.org/34441 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:
parent
f8efd03d99
commit
fe5545d591
3 changed files with 57 additions and 12 deletions
|
@ -93,7 +93,9 @@ loolnb_SOURCES = net/loolnb.cpp \
|
|||
common/Log.cpp \
|
||||
common/Util.cpp
|
||||
|
||||
clientnb_SOURCES = net/clientnb.cpp
|
||||
clientnb_SOURCES = net/clientnb.cpp \
|
||||
common/Log.cpp \
|
||||
common/Util.cpp
|
||||
|
||||
# build a binary with no caps to help debugging
|
||||
loolforkit_nocaps_SOURCES = $(loolforkit_SOURCES)
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#include <Poco/Runnable.h>
|
||||
#include <Poco/Thread.h>
|
||||
|
||||
#include "Util.hpp"
|
||||
|
||||
using Poco::Net::HTTPClientSession;
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPResponse;
|
||||
|
@ -192,9 +194,9 @@ struct Client : public Poco::Util::Application
|
|||
snakes[i].join();
|
||||
}
|
||||
|
||||
void testWebsocket()
|
||||
void testWebsocketPingPong()
|
||||
{
|
||||
std::cerr << "testwebsocket\n";
|
||||
std::cerr << "testWebsocketPingPong\n";
|
||||
Session session("ws", EnableHttps);
|
||||
std::shared_ptr<WebSocket> ws = session.getWebSocket();
|
||||
|
||||
|
@ -213,6 +215,36 @@ struct Client : public Poco::Util::Application
|
|||
}
|
||||
}
|
||||
|
||||
void testWebsocketEcho()
|
||||
{
|
||||
std::cerr << "testwebsocketEcho\n";
|
||||
Session session("ws", EnableHttps);
|
||||
std::shared_ptr<WebSocket> ws = session.getWebSocket();
|
||||
|
||||
std::vector<char> res;
|
||||
for (size_t i = 1; i < (1 << 14); ++i)
|
||||
{
|
||||
std::cerr << "\n" << i;
|
||||
const std::vector<char> data = Util::rng::getBytes(i);
|
||||
ws->sendFrame(data.data(), data.size(), WebSocket::SendFlags::FRAME_BINARY);
|
||||
|
||||
res.resize(i);
|
||||
int flags;
|
||||
int recvd = ws->receiveFrame(res.data(), res.size(), flags);
|
||||
assert(recvd == static_cast<int>(i));
|
||||
|
||||
if (i == sizeof(size_t))
|
||||
{
|
||||
assert(*reinterpret_cast<const size_t*>(res.data()) ==
|
||||
*reinterpret_cast<const size_t*>(data.data()) + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(res == data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
int main(const std::vector<std::string>& args) override
|
||||
{
|
||||
|
@ -230,7 +262,8 @@ public:
|
|||
Poco::Net::SSLManager::instance().initializeClient(nullptr, invalidCertHandler, sslContext);
|
||||
}
|
||||
|
||||
testWebsocket();
|
||||
testWebsocketPingPong();
|
||||
testWebsocketEcho();
|
||||
|
||||
testPing();
|
||||
testLadder();
|
||||
|
|
|
@ -249,15 +249,25 @@ public:
|
|||
else
|
||||
std::cerr << " binary\n";
|
||||
|
||||
// ping pong test
|
||||
assert (data.size() >= sizeof(size_t));
|
||||
size_t *countPtr = reinterpret_cast<size_t *>(&data[0]);
|
||||
size_t count = *countPtr;
|
||||
count++;
|
||||
std::cerr << "count is " << count << "\n";
|
||||
std::vector<char> reply;
|
||||
reply.insert(reply.end(), reinterpret_cast<char *>(&count),
|
||||
reinterpret_cast<char *>(&count) + sizeof(count));
|
||||
if (data.size() == sizeof(size_t))
|
||||
{
|
||||
// ping pong test
|
||||
assert (data.size() >= sizeof(size_t));
|
||||
size_t *countPtr = reinterpret_cast<size_t *>(&data[0]);
|
||||
size_t count = *countPtr;
|
||||
count++;
|
||||
std::cerr << "count is " << count << "\n";
|
||||
reply.insert(reply.end(), reinterpret_cast<char *>(&count),
|
||||
reinterpret_cast<char *>(&count) + sizeof(count));
|
||||
}
|
||||
else
|
||||
{
|
||||
// echo tests
|
||||
reply.insert(reply.end(), data.begin(), data.end());
|
||||
}
|
||||
|
||||
std::cerr << "reply: " << reply.size() << std::endl;
|
||||
queueWSMessage(reply);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue