mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
made client protocol test single threaded
This commit is contained in:
parent
8841ac40f8
commit
555058dbb5
21
include/webfuse/core/protocol_names.h
Normal file
21
include/webfuse/core/protocol_names.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// \file protocol_names.h
|
||||||
|
/// \brief Names of websocket protocol.
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef WF_PROTOCOL_NAMES_H
|
||||||
|
#define WF_PROTOCOL_NAMES_H
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/// \def WF_PROTOCOL_NAME_ADAPTER_SERVER
|
||||||
|
/// \brief Name of the websocket protocol an adapter server is running.
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
#define WF_PROTOCOL_NAME_ADAPTER_SERVER ("webfuse-adapter-server")
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/// \def WF_PROTOCOL_NAME_PROVIDER_CLIENT
|
||||||
|
/// \brief Name of the websocket protocol an provider client is running.
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
#define WF_PROTOCOL_NAME_PROVIDER_CLIENT ("webfuse-provider-client")
|
||||||
|
|
||||||
|
#endif
|
@ -7,6 +7,7 @@
|
|||||||
#define WF_ADAPTER_H
|
#define WF_ADAPTER_H
|
||||||
|
|
||||||
#include <webfuse/core/status.h>
|
#include <webfuse/core/status.h>
|
||||||
|
#include <webfuse/core/protocol_names.h>
|
||||||
|
|
||||||
#include <webfuse/adapter/api.h>
|
#include <webfuse/adapter/api.h>
|
||||||
#include <webfuse/adapter/server.h>
|
#include <webfuse/adapter/server.h>
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#define WF_PROVIDER_H
|
#define WF_PROVIDER_H
|
||||||
|
|
||||||
#include <webfuse/core/status.h>
|
#include <webfuse/core/status.h>
|
||||||
|
#include <webfuse/core/protocol_names.h>
|
||||||
|
|
||||||
#include <webfuse/provider/api.h>
|
#include <webfuse/provider/api.h>
|
||||||
#include <webfuse/provider/client.h>
|
#include <webfuse/provider/client.h>
|
||||||
|
@ -38,7 +38,6 @@ static struct lws_context * wf_impl_server_context_create(
|
|||||||
memset(server->ws_protocols, 0, sizeof(struct lws_protocols) * WF_SERVER_PROTOCOL_COUNT);
|
memset(server->ws_protocols, 0, sizeof(struct lws_protocols) * WF_SERVER_PROTOCOL_COUNT);
|
||||||
server->ws_protocols[0].name = "http";
|
server->ws_protocols[0].name = "http";
|
||||||
server->ws_protocols[0].callback = lws_callback_http_dummy;
|
server->ws_protocols[0].callback = lws_callback_http_dummy;
|
||||||
server->ws_protocols[1].name = "fs";
|
|
||||||
wf_impl_server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]);
|
wf_impl_server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]);
|
||||||
|
|
||||||
memset(&server->mount, 0, sizeof(struct lws_http_mount));
|
memset(&server->mount, 0, sizeof(struct lws_http_mount));
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "webfuse/core/message.h"
|
#include "webfuse/core/message.h"
|
||||||
#include "webfuse/core/util.h"
|
#include "webfuse/core/util.h"
|
||||||
|
#include "webfuse/core/protocol_names.h"
|
||||||
|
|
||||||
#include "webfuse/adapter/impl/credentials.h"
|
#include "webfuse/adapter/impl/credentials.h"
|
||||||
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
||||||
@ -121,6 +122,7 @@ void wf_impl_server_protocol_init_lws(
|
|||||||
struct wf_server_protocol * protocol,
|
struct wf_server_protocol * protocol,
|
||||||
struct lws_protocols * lws_protocol)
|
struct lws_protocols * lws_protocol)
|
||||||
{
|
{
|
||||||
|
lws_protocol->name = WF_PROTOCOL_NAME_ADAPTER_SERVER;
|
||||||
lws_protocol->callback = &wf_impl_server_protocol_callback;
|
lws_protocol->callback = &wf_impl_server_protocol_callback;
|
||||||
lws_protocol->per_session_data_size = 0;
|
lws_protocol->per_session_data_size = 0;
|
||||||
lws_protocol->user = protocol;
|
lws_protocol->user = protocol;
|
||||||
|
@ -35,7 +35,6 @@ struct wfp_client * wfp_impl_client_create(
|
|||||||
wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
|
wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
|
||||||
|
|
||||||
memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT);
|
memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT);
|
||||||
client->protocols[0].name = WFP_CLIENT_PROTOCOL_NAME;
|
|
||||||
wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
|
wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
|
||||||
|
|
||||||
memset(&client->info, 0, sizeof(struct lws_context_creation_info));
|
memset(&client->info, 0, sizeof(struct lws_context_creation_info));
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <libwebsockets.h>
|
#include <libwebsockets.h>
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
|
|
||||||
|
|
||||||
#include "webfuse/provider/impl/client_config.h"
|
#include "webfuse/provider/impl/client_config.h"
|
||||||
#include "webfuse/provider/impl/provider.h"
|
#include "webfuse/provider/impl/provider.h"
|
||||||
#include "webfuse/core/util.h"
|
#include "webfuse/core/util.h"
|
||||||
@ -14,6 +13,7 @@
|
|||||||
#include "webfuse/core/message_queue.h"
|
#include "webfuse/core/message_queue.h"
|
||||||
#include "webfuse/core/container_of.h"
|
#include "webfuse/core/container_of.h"
|
||||||
#include "webfuse/provider/impl/url.h"
|
#include "webfuse/provider/impl/url.h"
|
||||||
|
#include "webfuse/core/protocol_names.h"
|
||||||
|
|
||||||
static void wfp_impl_client_protocol_respond(
|
static void wfp_impl_client_protocol_respond(
|
||||||
json_t * response,
|
json_t * response,
|
||||||
@ -180,6 +180,7 @@ void wfp_impl_client_protocol_init_lws(
|
|||||||
struct wfp_client_protocol * protocol,
|
struct wfp_client_protocol * protocol,
|
||||||
struct lws_protocols * lws_protocol)
|
struct lws_protocols * lws_protocol)
|
||||||
{
|
{
|
||||||
|
lws_protocol->name = WF_PROTOCOL_NAME_PROVIDER_CLIENT;
|
||||||
lws_protocol->callback = &wfp_impl_client_protocol_callback;
|
lws_protocol->callback = &wfp_impl_client_protocol_callback;
|
||||||
lws_protocol->per_session_data_size = 0;
|
lws_protocol->per_session_data_size = 0;
|
||||||
lws_protocol->user = protocol;
|
lws_protocol->user = protocol;
|
||||||
@ -203,7 +204,8 @@ void wfp_impl_client_protocol_connect(
|
|||||||
info.host = info.address;
|
info.host = info.address;
|
||||||
info.origin = info.address;
|
info.origin = info.address;
|
||||||
info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0;
|
info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0;
|
||||||
info.protocol = WFP_CLIENT_PROTOCOL_NAME;
|
info.protocol = WF_PROTOCOL_NAME_ADAPTER_SERVER;
|
||||||
|
info.local_protocol_name = WF_PROTOCOL_NAME_PROVIDER_CLIENT;
|
||||||
info.pwsi = &protocol->wsi;
|
info.pwsi = &protocol->wsi;
|
||||||
|
|
||||||
lws_client_connect_via_info(&info);
|
lws_client_connect_via_info(&info);
|
||||||
|
@ -11,8 +11,6 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WFP_CLIENT_PROTOCOL_NAME ("fs")
|
|
||||||
|
|
||||||
struct wfp_client_config;
|
struct wfp_client_config;
|
||||||
struct lws_protocols;
|
struct lws_protocols;
|
||||||
struct lws_context;
|
struct lws_context;
|
||||||
|
@ -22,7 +22,6 @@ public:
|
|||||||
: server(nullptr)
|
: server(nullptr)
|
||||||
, config(nullptr)
|
, config(nullptr)
|
||||||
, protocol(nullptr)
|
, protocol(nullptr)
|
||||||
, context(nullptr)
|
|
||||||
{
|
{
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
@ -30,41 +29,29 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void SetUp()
|
void SetUp()
|
||||||
{
|
{
|
||||||
server = new WebsocketServer(54321);
|
|
||||||
|
|
||||||
config = wfp_client_config_create();
|
config = wfp_client_config_create();
|
||||||
protocol = wfp_client_protocol_create(config);
|
protocol = wfp_client_protocol_create(config);
|
||||||
|
|
||||||
struct lws_protocols protocols[2];
|
struct lws_protocols client_protocol;
|
||||||
memset(protocols, 0, sizeof(struct lws_protocols) * 2);
|
memset(&client_protocol, 0, sizeof(struct lws_protocols));
|
||||||
protocols[0].name = "fs";
|
wfp_client_protocol_init_lws(protocol, &client_protocol);
|
||||||
wfp_client_protocol_init_lws(protocol, &protocols[0]);
|
|
||||||
|
|
||||||
struct lws_context_creation_info info;
|
server = new WebsocketServer(54321, &client_protocol, 1);
|
||||||
memset(&info, 0, sizeof(struct lws_context_creation_info));
|
|
||||||
info.port = CONTEXT_PORT_NO_LISTEN;
|
|
||||||
info.protocols = protocols;
|
|
||||||
info.uid = -1;
|
|
||||||
info.gid = -1;
|
|
||||||
|
|
||||||
context = lws_create_context(&info);
|
|
||||||
wfp_client_protocol_connect(protocol, context, "ws://localhost:54321/");
|
|
||||||
|
|
||||||
isShutdownRequested = false;
|
|
||||||
thread = std::thread(run, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TearDown()
|
void TearDown()
|
||||||
{
|
{
|
||||||
isShutdownRequested = true;
|
delete server;
|
||||||
thread.join();
|
|
||||||
|
|
||||||
lws_context_destroy(context);
|
|
||||||
|
|
||||||
wfp_client_protocol_dispose(protocol);
|
wfp_client_protocol_dispose(protocol);
|
||||||
wfp_client_config_dispose(config);
|
wfp_client_config_dispose(config);
|
||||||
|
|
||||||
delete server;
|
}
|
||||||
|
|
||||||
|
void connect()
|
||||||
|
{
|
||||||
|
wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/");
|
||||||
|
server->waitForConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void awaitAddFilesystem(std::string& filesystemName)
|
void awaitAddFilesystem(std::string& filesystemName)
|
||||||
@ -103,20 +90,8 @@ protected:
|
|||||||
WebsocketServer * server;
|
WebsocketServer * server;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void run(ClientProtocolTest * self)
|
|
||||||
{
|
|
||||||
while (!self->isShutdownRequested)
|
|
||||||
{
|
|
||||||
lws_service(self->context, 100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wfp_client_config * config;
|
wfp_client_config * config;
|
||||||
wfp_client_protocol * protocol;
|
wfp_client_protocol * protocol;
|
||||||
std::thread thread;
|
|
||||||
std::atomic<bool> isShutdownRequested;
|
|
||||||
lws_context * context;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -126,12 +101,14 @@ private:
|
|||||||
|
|
||||||
TEST_F(ClientProtocolTest, connect)
|
TEST_F(ClientProtocolTest, connect)
|
||||||
{
|
{
|
||||||
server->waitForConnection();
|
connect();
|
||||||
|
if (HasFatalFailure()) { return; }
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ClientProtocolTest, getattr)
|
TEST_F(ClientProtocolTest, getattr)
|
||||||
{
|
{
|
||||||
server->waitForConnection();
|
connect();
|
||||||
|
if (HasFatalFailure()) { return; }
|
||||||
|
|
||||||
std::string filesystem;
|
std::string filesystem;
|
||||||
awaitAddFilesystem(filesystem);
|
awaitAddFilesystem(filesystem);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "webfuse/utils/timeout_watcher.hpp"
|
#include "webfuse/utils/timeout_watcher.hpp"
|
||||||
|
|
||||||
#include "webfuse/core/util.h"
|
#include "webfuse/core/util.h"
|
||||||
|
#include "webfuse/core/protocol_names.h"
|
||||||
#include <libwebsockets.h>
|
#include <libwebsockets.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -76,15 +77,22 @@ namespace webfuse_test
|
|||||||
class WebsocketServer::Private: public IServer
|
class WebsocketServer::Private: public IServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Private(int port)
|
Private(int port, struct lws_protocols * additionalProtocols, size_t additionalProtocolsCount)
|
||||||
: client_wsi(nullptr)
|
: client_wsi(nullptr)
|
||||||
{
|
{
|
||||||
memset(ws_protocols, 0, sizeof(struct lws_protocols) * 2);
|
ws_protocols = new struct lws_protocols[2 + additionalProtocolsCount];
|
||||||
ws_protocols[0].name = "fs";
|
memset(ws_protocols, 0, sizeof(struct lws_protocols) * (2 + additionalProtocolsCount));
|
||||||
|
|
||||||
|
ws_protocols[0].name = WF_PROTOCOL_NAME_ADAPTER_SERVER;
|
||||||
ws_protocols[0].callback = &wf_test_utils_ws_server_callback;
|
ws_protocols[0].callback = &wf_test_utils_ws_server_callback;
|
||||||
ws_protocols[0].per_session_data_size = 0;
|
ws_protocols[0].per_session_data_size = 0;
|
||||||
ws_protocols[0].user = reinterpret_cast<void*>(this);
|
ws_protocols[0].user = reinterpret_cast<void*>(this);
|
||||||
|
|
||||||
|
if (0 < additionalProtocolsCount)
|
||||||
|
{
|
||||||
|
memcpy(&ws_protocols[additionalProtocolsCount], additionalProtocols, sizeof(struct lws_protocols) * additionalProtocolsCount);
|
||||||
|
}
|
||||||
|
|
||||||
memset(&info, 0, sizeof(struct lws_context_creation_info));
|
memset(&info, 0, sizeof(struct lws_context_creation_info));
|
||||||
info.port = port;
|
info.port = port;
|
||||||
info.mounts = NULL;
|
info.mounts = NULL;
|
||||||
@ -94,11 +102,18 @@ public:
|
|||||||
info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE;
|
info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE;
|
||||||
|
|
||||||
context = lws_create_context(&info);
|
context = lws_create_context(&info);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Private()
|
virtual ~Private()
|
||||||
{
|
{
|
||||||
lws_context_destroy(context);
|
lws_context_destroy(context);
|
||||||
|
delete[] ws_protocols;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct lws_context * getContext()
|
||||||
|
{
|
||||||
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitForConnection()
|
void waitForConnection()
|
||||||
@ -130,7 +145,6 @@ public:
|
|||||||
lws_service(context, 100);
|
lws_service(context, 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
json_t * receiveMessage()
|
json_t * receiveMessage()
|
||||||
@ -203,7 +217,7 @@ private:
|
|||||||
|
|
||||||
struct lws * client_wsi;
|
struct lws * client_wsi;
|
||||||
|
|
||||||
struct lws_protocols ws_protocols[2];
|
struct lws_protocols * ws_protocols;
|
||||||
struct lws_context_creation_info info;
|
struct lws_context_creation_info info;
|
||||||
struct lws_context * context;
|
struct lws_context * context;
|
||||||
std::queue<std::string> writeQueue;
|
std::queue<std::string> writeQueue;
|
||||||
@ -212,7 +226,13 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
WebsocketServer::WebsocketServer(int port)
|
WebsocketServer::WebsocketServer(int port)
|
||||||
: d(new Private(port))
|
: d(new Private(port, nullptr, 0))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WebsocketServer::WebsocketServer(int port, struct lws_protocols * additionalProtocols, std::size_t additionalProtocolsCount)
|
||||||
|
: d(new Private(port, additionalProtocols, additionalProtocolsCount))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -222,6 +242,11 @@ WebsocketServer::~WebsocketServer()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct lws_context * WebsocketServer::getContext()
|
||||||
|
{
|
||||||
|
return d->getContext();
|
||||||
|
}
|
||||||
|
|
||||||
void WebsocketServer::waitForConnection()
|
void WebsocketServer::waitForConnection()
|
||||||
{
|
{
|
||||||
d->waitForConnection();
|
d->waitForConnection();
|
||||||
|
@ -13,7 +13,9 @@ class WebsocketServer
|
|||||||
WebsocketServer & operator=(WebsocketServer const &) = delete;
|
WebsocketServer & operator=(WebsocketServer const &) = delete;
|
||||||
public:
|
public:
|
||||||
explicit WebsocketServer(int port);
|
explicit WebsocketServer(int port);
|
||||||
|
WebsocketServer(int port, struct lws_protocols * additionalProtocols, std::size_t additionalProtocolsCount);
|
||||||
~WebsocketServer();
|
~WebsocketServer();
|
||||||
|
struct lws_context * getContext();
|
||||||
void waitForConnection();
|
void waitForConnection();
|
||||||
void sendMessage(json_t * message);
|
void sendMessage(json_t * message);
|
||||||
json_t * receiveMessage();
|
json_t * receiveMessage();
|
||||||
|
Loading…
Reference in New Issue
Block a user