0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-28 00:14:07 +01:00

construct: Add smoketest.

This commit is contained in:
Jason Volk 2019-04-24 01:01:48 -07:00
parent 87210d4856
commit dd4090e11b

View file

@ -37,6 +37,8 @@ bool norun;
bool read_only;
bool write_avoid;
const char *execute;
std::array<bool, 6> smoketest;
lgetopt opts[]
{
{ "help", nullptr, lgetopt::USAGE, "Print this text" },
@ -56,6 +58,7 @@ lgetopt opts[]
{ "norun", &norun, lgetopt::BOOL, "[debug & testing only] Initialize but never run the event loop." },
{ "ro", &read_only, lgetopt::BOOL, "Read-only mode. No writes to database allowed." },
{ "wa", &write_avoid, lgetopt::BOOL, "Like read-only mode, but writes permitted if triggered." },
{ "smoketest", &smoketest[0], lgetopt::BOOL, "Starts and stops the daemon to return success."},
{ nullptr, nullptr, lgetopt::STRING, nullptr },
};
@ -137,6 +140,17 @@ noexcept try
"Must specify the origin after any switched parameters."
};
// The smoketest uses this ircd::run::level callback to set a flag when
// each ircd::run::level is reached. All flags must be set to pass.
const ircd::run::changed smoketester{[](const auto &level)
{
smoketest.at(size_t(level) + 1) = true;
if(smoketest[0] && level == ircd::run::level::RUN) ircd::post{[]
{
ircd::quit();
}};
}};
// This is the sole io_context for Construct, and the ios.run() below is the
// the only place where the program actually blocks.
boost::asio::io_context ios;
@ -175,6 +189,13 @@ noexcept try
// Blocks until a clean exit from a quit() or an exception comes out of it.
ios.run();
// The smoketest is enabled if the first value is true; then all of the
// values must be true for the smoketest to pass.
if(smoketest[0])
return std::count(begin(smoketest), end(smoketest), true) == smoketest.size()?
EXIT_SUCCESS:
EXIT_FAILURE;
// The restart flag can be set by the console command "restart" which
// calls ircd::quit() to clean break from the run() loop.
if(ircd::restart)