mirror of
https://github.com/matrix-construct/construct
synced 2025-01-16 01:26:58 +01:00
construct: Add smoketest.
This commit is contained in:
parent
87210d4856
commit
dd4090e11b
1 changed files with 21 additions and 0 deletions
|
@ -37,6 +37,8 @@ bool norun;
|
||||||
bool read_only;
|
bool read_only;
|
||||||
bool write_avoid;
|
bool write_avoid;
|
||||||
const char *execute;
|
const char *execute;
|
||||||
|
std::array<bool, 6> smoketest;
|
||||||
|
|
||||||
lgetopt opts[]
|
lgetopt opts[]
|
||||||
{
|
{
|
||||||
{ "help", nullptr, lgetopt::USAGE, "Print this text" },
|
{ "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." },
|
{ "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." },
|
{ "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." },
|
{ "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 },
|
{ nullptr, nullptr, lgetopt::STRING, nullptr },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -137,6 +140,17 @@ noexcept try
|
||||||
"Must specify the origin after any switched parameters."
|
"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
|
// This is the sole io_context for Construct, and the ios.run() below is the
|
||||||
// the only place where the program actually blocks.
|
// the only place where the program actually blocks.
|
||||||
boost::asio::io_context ios;
|
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.
|
// Blocks until a clean exit from a quit() or an exception comes out of it.
|
||||||
ios.run();
|
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
|
// The restart flag can be set by the console command "restart" which
|
||||||
// calls ircd::quit() to clean break from the run() loop.
|
// calls ircd::quit() to clean break from the run() loop.
|
||||||
if(ircd::restart)
|
if(ircd::restart)
|
||||||
|
|
Loading…
Reference in a new issue