Fix limit setting and add ServerImp tests (RIPD-1463,1458):

Add more test coverage for ServerHandlerImp.cpp. Ensure limit parameter
is propagated from parsed object to in-memory config.

Release Notes
-------------

This fixes a bug whereby the limit parameter on a port configuration was
ignored.
This commit is contained in:
Mike Ellery
2017-04-17 13:09:30 -07:00
committed by seelabs
parent 3c37539cee
commit fc89d2e014
6 changed files with 716 additions and 167 deletions

View File

@@ -23,6 +23,9 @@
#include <ripple/server/Server.h>
#include <ripple/server/Session.h>
#include <ripple/beast/unit_test.h>
#include <ripple/core/ConfigSections.h>
#include <test/jtx.h>
#include <test/jtx/envconfig.h>
#include <boost/asio.hpp>
#include <boost/optional.hpp>
#include <boost/utility/in_place_factory.hpp>
@@ -367,11 +370,186 @@ public:
}
}
/**
* @brief sink for writing all log messages to a stringstream
*/
class CaptureSink : public beast::Journal::Sink
{
std::stringstream& strm_;
public:
CaptureSink(beast::severities::Severity threshold,
std::stringstream& strm)
: beast::Journal::Sink(threshold, false)
, strm_(strm)
{
}
void
write(beast::severities::Severity level, std::string const& text) override
{
strm_ << text;
}
};
/**
* @brief Log manager for CaptureSinks. This class holds the stream
* instance that is written to by the sinks. Upon destruction, all
* contents of the stream are assigned to the string specified in the
* ctor
*/
class CaptureLogs : public Logs
{
std::stringstream strm_;
std::string& result_;
public:
CaptureLogs(std::string& result)
: Logs (beast::severities::kInfo)
, result_(result)
{
}
~CaptureLogs() override
{
result_ = strm_.str();
}
std::unique_ptr<beast::Journal::Sink>
makeSink(std::string const& partition,
beast::severities::Severity threshold) override
{
return std::make_unique<CaptureSink>(threshold, strm_);
}
};
void
testBadConfig ()
{
testcase ("Server config - invalid options");
using namespace test::jtx;
std::string messages;
except ([&]
{
Env env {*this,
envconfig([](std::unique_ptr<Config> cfg) {
(*cfg).deprecatedClearSection("port_rpc");
return cfg;
}),
std::make_unique<CaptureLogs>(messages)};
});
BEAST_EXPECT (
messages.find ("Missing 'ip' in [port_rpc]")
!= std::string::npos);
except ([&]
{
Env env {*this,
envconfig([](std::unique_ptr<Config> cfg) {
(*cfg).deprecatedClearSection("port_rpc");
(*cfg)["port_rpc"].set("ip", "127.0.0.1");
return cfg;
}),
std::make_unique<CaptureLogs>(messages)};
});
BEAST_EXPECT (
messages.find ("Missing 'port' in [port_rpc]")
!= std::string::npos);
except ([&]
{
Env env {*this,
envconfig([](std::unique_ptr<Config> cfg) {
(*cfg).deprecatedClearSection("port_rpc");
(*cfg)["port_rpc"].set("ip", "127.0.0.1");
(*cfg)["port_rpc"].set("port", "0");
return cfg;
}),
std::make_unique<CaptureLogs>(messages)};
});
BEAST_EXPECT (
messages.find ("Invalid value '0' for key 'port' in [port_rpc]")
!= std::string::npos);
except ([&]
{
Env env {*this,
envconfig([](std::unique_ptr<Config> cfg) {
(*cfg).deprecatedClearSection("port_rpc");
(*cfg)["port_rpc"].set("ip", "127.0.0.1");
(*cfg)["port_rpc"].set("port", "8081");
(*cfg)["port_rpc"].set("protocol", "");
return cfg;
}),
std::make_unique<CaptureLogs>(messages)};
});
BEAST_EXPECT (
messages.find ("Missing 'protocol' in [port_rpc]")
!= std::string::npos);
except ([&] //this creates a standard test config without the server
//section
{
Env env {*this,
envconfig([](std::unique_ptr<Config> cfg) {
cfg = std::make_unique<Config>();
cfg->overwrite (
ConfigSection::nodeDatabase (), "type", "memory");
cfg->overwrite (
ConfigSection::nodeDatabase (), "path", "main");
cfg->deprecatedClearSection (
ConfigSection::importNodeDatabase ());
cfg->legacy("database_path", "");
cfg->setupControl(true, true, true);
(*cfg)["port_peer"].set("ip", "127.0.0.1");
(*cfg)["port_peer"].set("port", "8080");
(*cfg)["port_peer"].set("protocol", "peer");
(*cfg)["port_rpc"].set("ip", "127.0.0.1");
(*cfg)["port_rpc"].set("port", "8081");
(*cfg)["port_rpc"].set("protocol", "http,ws2");
(*cfg)["port_rpc"].set("admin", "127.0.0.1");
(*cfg)["port_ws"].set("ip", "127.0.0.1");
(*cfg)["port_ws"].set("port", "8082");
(*cfg)["port_ws"].set("protocol", "ws");
(*cfg)["port_ws"].set("admin", "127.0.0.1");
return cfg;
}),
std::make_unique<CaptureLogs>(messages)};
});
BEAST_EXPECT (
messages.find ("Required section [server] is missing")
!= std::string::npos);
except ([&] //this creates a standard test config without some of the
//port sections
{
Env env {*this,
envconfig([](std::unique_ptr<Config> cfg) {
cfg = std::make_unique<Config>();
cfg->overwrite (ConfigSection::nodeDatabase (), "type", "memory");
cfg->overwrite (ConfigSection::nodeDatabase (), "path", "main");
cfg->deprecatedClearSection (ConfigSection::importNodeDatabase ());
cfg->legacy("database_path", "");
cfg->setupControl(true, true, true);
(*cfg)["server"].append("port_peer");
(*cfg)["server"].append("port_rpc");
(*cfg)["server"].append("port_ws");
return cfg;
}),
std::make_unique<CaptureLogs>(messages)};
});
BEAST_EXPECT (
messages.find ("Missing section: [port_peer]")
!= std::string::npos);
}
void
run()
{
basicTests();
stressTest();
testBadConfig();
}
};