mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
chore: Add counter for total messages waiting to be sent (#1691)
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "util/MockPrometheus.hpp"
|
||||
#include "util/TestHttpSyncClient.hpp"
|
||||
#include "util/config/Config.hpp"
|
||||
#include "util/prometheus/Gauge.hpp"
|
||||
#include "util/prometheus/Label.hpp"
|
||||
#include "util/prometheus/Prometheus.hpp"
|
||||
#include "web/Server.hpp"
|
||||
@@ -42,6 +43,7 @@
|
||||
#include <boost/json/value.hpp>
|
||||
#include <boost/system/system_error.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <condition_variable>
|
||||
@@ -144,6 +146,8 @@ private:
|
||||
std::optional<std::thread> runner;
|
||||
};
|
||||
|
||||
struct WebServerTestsWithMockPrometheus : WebServerTest, prometheus::WithMockPrometheus {};
|
||||
|
||||
class EchoExecutor {
|
||||
public:
|
||||
void
|
||||
@@ -204,7 +208,7 @@ makeServerSync(
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_F(WebServerTest, Http)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, Http)
|
||||
{
|
||||
auto e = std::make_shared<EchoExecutor>();
|
||||
auto const server = makeServerSync(cfg, ctx, dosGuard, e);
|
||||
@@ -212,8 +216,13 @@ TEST_F(WebServerTest, Http)
|
||||
EXPECT_EQ(res, R"({"Hello":1})");
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, Ws)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, Ws)
|
||||
{
|
||||
::testing::StrictMock<util::prometheus::MockCounterImplInt>& wsMessagesCounterMock =
|
||||
makeMock<util::prometheus::GaugeInt>("ws_messages_length", "");
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(1));
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(-1));
|
||||
|
||||
auto e = std::make_shared<EchoExecutor>();
|
||||
auto const server = makeServerSync(cfg, ctx, dosGuard, e);
|
||||
WebSocketSyncClient wsClient;
|
||||
@@ -223,7 +232,7 @@ TEST_F(WebServerTest, Ws)
|
||||
wsClient.disconnect();
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, HttpInternalError)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, HttpInternalError)
|
||||
{
|
||||
auto e = std::make_shared<ExceptionExecutor>();
|
||||
auto const server = makeServerSync(cfg, ctx, dosGuard, e);
|
||||
@@ -234,8 +243,13 @@ TEST_F(WebServerTest, HttpInternalError)
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, WsInternalError)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, WsInternalError)
|
||||
{
|
||||
::testing::StrictMock<util::prometheus::MockCounterImplInt>& wsMessagesCounterMock =
|
||||
makeMock<util::prometheus::GaugeInt>("ws_messages_length", "");
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(1));
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(-1));
|
||||
|
||||
auto e = std::make_shared<ExceptionExecutor>();
|
||||
auto const server = makeServerSync(cfg, ctx, dosGuard, e);
|
||||
WebSocketSyncClient wsClient;
|
||||
@@ -248,8 +262,13 @@ TEST_F(WebServerTest, WsInternalError)
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, WsInternalErrorNotJson)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, WsInternalErrorNotJson)
|
||||
{
|
||||
::testing::StrictMock<util::prometheus::MockCounterImplInt>& wsMessagesCounterMock =
|
||||
makeMock<util::prometheus::GaugeInt>("ws_messages_length", "");
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(1));
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(-1));
|
||||
|
||||
auto e = std::make_shared<ExceptionExecutor>();
|
||||
auto const server = makeServerSync(cfg, ctx, dosGuard, e);
|
||||
WebSocketSyncClient wsClient;
|
||||
@@ -262,7 +281,7 @@ TEST_F(WebServerTest, WsInternalErrorNotJson)
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, IncompleteSslConfig)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, IncompleteSslConfig)
|
||||
{
|
||||
auto e = std::make_shared<EchoExecutor>();
|
||||
|
||||
@@ -273,7 +292,7 @@ TEST_F(WebServerTest, IncompleteSslConfig)
|
||||
EXPECT_EQ(server, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, WrongSslConfig)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, WrongSslConfig)
|
||||
{
|
||||
auto e = std::make_shared<EchoExecutor>();
|
||||
|
||||
@@ -285,7 +304,7 @@ TEST_F(WebServerTest, WrongSslConfig)
|
||||
EXPECT_EQ(server, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, Https)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, Https)
|
||||
{
|
||||
auto e = std::make_shared<EchoExecutor>();
|
||||
cfg = Config{addSslConfig(generateJSONWithDynamicPort(port))};
|
||||
@@ -294,8 +313,13 @@ TEST_F(WebServerTest, Https)
|
||||
EXPECT_EQ(res, R"({"Hello":1})");
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, Wss)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, Wss)
|
||||
{
|
||||
::testing::StrictMock<util::prometheus::MockCounterImplInt>& wsMessagesCounterMock =
|
||||
makeMock<util::prometheus::GaugeInt>("ws_messages_length", "");
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(1));
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(-1));
|
||||
|
||||
auto e = std::make_shared<EchoExecutor>();
|
||||
cfg = Config{addSslConfig(generateJSONWithDynamicPort(port))};
|
||||
auto server = makeServerSync(cfg, ctx, dosGuard, e);
|
||||
@@ -306,7 +330,7 @@ TEST_F(WebServerTest, Wss)
|
||||
wsClient.disconnect();
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, HttpRequestOverload)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, HttpRequestOverload)
|
||||
{
|
||||
auto e = std::make_shared<EchoExecutor>();
|
||||
auto const server = makeServerSync(cfg, ctx, dosGuardOverload, e);
|
||||
@@ -319,8 +343,13 @@ TEST_F(WebServerTest, HttpRequestOverload)
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, WsRequestOverload)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, WsRequestOverload)
|
||||
{
|
||||
::testing::StrictMock<util::prometheus::MockCounterImplInt>& wsMessagesCounterMock =
|
||||
makeMock<util::prometheus::GaugeInt>("ws_messages_length", "");
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(1)).Times(2);
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(-1)).Times(2);
|
||||
|
||||
auto e = std::make_shared<EchoExecutor>();
|
||||
auto const server = makeServerSync(cfg, ctx, dosGuardOverload, e);
|
||||
WebSocketSyncClient wsClient;
|
||||
@@ -338,7 +367,7 @@ TEST_F(WebServerTest, WsRequestOverload)
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, HttpPayloadOverload)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, HttpPayloadOverload)
|
||||
{
|
||||
std::string const s100(100, 'a');
|
||||
auto e = std::make_shared<EchoExecutor>();
|
||||
@@ -350,8 +379,13 @@ TEST_F(WebServerTest, HttpPayloadOverload)
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, WsPayloadOverload)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, WsPayloadOverload)
|
||||
{
|
||||
::testing::StrictMock<util::prometheus::MockCounterImplInt>& wsMessagesCounterMock =
|
||||
makeMock<util::prometheus::GaugeInt>("ws_messages_length", "");
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(1));
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(-1));
|
||||
|
||||
std::string const s100(100, 'a');
|
||||
auto e = std::make_shared<EchoExecutor>();
|
||||
auto server = makeServerSync(cfg, ctx, dosGuardOverload, e);
|
||||
@@ -365,7 +399,7 @@ TEST_F(WebServerTest, WsPayloadOverload)
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(WebServerTest, WsTooManyConnection)
|
||||
TEST_F(WebServerTestsWithMockPrometheus, WsTooManyConnection)
|
||||
{
|
||||
auto e = std::make_shared<EchoExecutor>();
|
||||
auto server = makeServerSync(cfg, ctx, dosGuardOverload, e);
|
||||
@@ -471,10 +505,17 @@ struct WebServerAdminTestParams {
|
||||
std::string expectedResponse;
|
||||
};
|
||||
|
||||
class WebServerAdminTest : public WebServerTest, public ::testing::WithParamInterface<WebServerAdminTestParams> {};
|
||||
class WebServerAdminTest : public WebServerTest,
|
||||
public ::testing::WithParamInterface<WebServerAdminTestParams>,
|
||||
public prometheus::WithMockPrometheus {};
|
||||
|
||||
TEST_P(WebServerAdminTest, WsAdminCheck)
|
||||
{
|
||||
::testing::StrictMock<util::prometheus::MockCounterImplInt>& wsMessagesCounterMock =
|
||||
makeMock<util::prometheus::GaugeInt>("ws_messages_length", "");
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(1));
|
||||
EXPECT_CALL(wsMessagesCounterMock, add(-1));
|
||||
|
||||
auto e = std::make_shared<AdminCheckExecutor>();
|
||||
Config const serverConfig{boost::json::parse(GetParam().config)};
|
||||
auto server = makeServerSync(serverConfig, ctx, dosGuardOverload, e);
|
||||
|
||||
Reference in New Issue
Block a user