diff options
author | Nathan Brown <nathan.brown@10gen.com> | 2019-05-31 18:03:18 -0400 |
---|---|---|
committer | Nathan Brown <nathan.brown@10gen.com> | 2019-06-07 16:32:48 -0400 |
commit | c69e513070d03c0ed7a3a32047b39885fa5464c6 (patch) | |
tree | 1987f7a8af7c9f9e1ec92cac2b8483cc4e4c0e94 | |
parent | 06bf03568dc44fd53485fcf3a955c7faa8252fe7 (diff) | |
download | mongo-c69e513070d03c0ed7a3a32047b39885fa5464c6.tar.gz |
SERVER-18463 Remove StartupTest infrastructure, place StartupTests into
unittests
-rw-r--r-- | src/mongo/SConscript | 10 | ||||
-rw-r--r-- | src/mongo/db/cursor_manager.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/db.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/hasher.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 1 | ||||
-rw-r--r-- | src/mongo/dbtests/dbtests.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/mongos_options.cpp | 2 | ||||
-rw-r--r-- | src/mongo/shell/SConscript | 31 | ||||
-rw-r--r-- | src/mongo/shell/dbshell.cpp | 162 | ||||
-rw-r--r-- | src/mongo/shell/shell_utils.cpp | 126 | ||||
-rw-r--r-- | src/mongo/shell/shell_utils.h | 2 | ||||
-rw-r--r-- | src/mongo/shell/shell_utils_test.cpp | 81 | ||||
-rw-r--r-- | src/mongo/util/startup_test.cpp | 56 | ||||
-rw-r--r-- | src/mongo/util/startup_test.h | 70 |
14 files changed, 243 insertions, 312 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index ce0fc27a358..1662fdd3642 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -131,7 +131,6 @@ env.Library( 'util/signal_handlers_synchronous.cpp', 'util/stacktrace.cpp', 'util/stacktrace_${TARGET_OS_FAMILY}.cpp', - 'util/startup_test.cpp', 'util/str.cpp', 'util/system_clock_source.cpp', 'util/system_tick_source.cpp', @@ -566,12 +565,7 @@ if not has_option('noshell') and usemozjs: shell_core_env.Library("shell_core", source=[ "shell/linenoise.cpp", - "shell/mk_wcwidth.cpp", - "shell/mongo-server.cpp", - "shell/shell_options.cpp", - "shell/shell_utils.cpp", - "shell/shell_utils_extended.cpp", - "shell/shell_utils_launcher.cpp", + "shell/mk_wcwidth.cpp" ], LIBDEPS=[ 'client/clientdriver_network', @@ -587,7 +581,7 @@ if not has_option('noshell') and usemozjs: 'scripting/scripting', 'shell/benchrun', 'shell/mongojs', - 'shell/shell_options_storage', + 'shell/shell_utils', 'transport/message_compressor', 'transport/transport_layer_manager', 'util/net/network', diff --git a/src/mongo/db/cursor_manager.cpp b/src/mongo/db/cursor_manager.cpp index a577689f4dc..978245df357 100644 --- a/src/mongo/db/cursor_manager.cpp +++ b/src/mongo/db/cursor_manager.cpp @@ -54,7 +54,6 @@ #include "mongo/stdx/memory.h" #include "mongo/util/exit.h" #include "mongo/util/log.h" -#include "mongo/util/startup_test.h" namespace mongo { diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index 5d58f604880..32eb25ef96f 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -177,7 +177,6 @@ #include "mongo/util/sequence_util.h" #include "mongo/util/signal_handlers.h" #include "mongo/util/stacktrace.h" -#include "mongo/util/startup_test.h" #include "mongo/util/text.h" #include "mongo/util/time_support.h" #include "mongo/util/version.h" @@ -1079,7 +1078,6 @@ int mongoDbMain(int argc, char* argv[], char** envp) { } #endif - StartupTest::runTests(); ExitCode exitCode = initAndListen(serverGlobalParams.port); exitCleanly(exitCode); return 0; diff --git a/src/mongo/db/hasher.cpp b/src/mongo/db/hasher.cpp index 677d34d9b7f..e8da6919bf4 100644 --- a/src/mongo/db/hasher.cpp +++ b/src/mongo/db/hasher.cpp @@ -36,7 +36,6 @@ #include "mongo/db/jsobj.h" #include "mongo/util/md5.hpp" -#include "mongo/util/startup_test.h" namespace mongo { @@ -137,14 +136,6 @@ void recursiveHash(Hasher* h, const BSONElement& e, bool includeFieldName) { } } -struct HasherUnitTest : public StartupTest { - void run() { - // Hard-coded check to ensure the hash function is consistent across platforms - BSONObj o = BSON("check" << 42); - verify(BSONElementHasher::hash64(o.firstElement(), 0) == -944302157085130861LL); - } -} hasherUnitTest; - } // namespace long long int BSONElementHasher::hash64(const BSONElement& e, HashSeed seed) { diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 658353d6cad..11fa6719a1c 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -94,7 +94,6 @@ #include "mongo/util/fail_point_service.h" #include "mongo/util/file.h" #include "mongo/util/log.h" -#include "mongo/util/startup_test.h" #include "mongo/util/str.h" namespace mongo { diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp index 3a16b947f98..1fefee04e74 100644 --- a/src/mongo/dbtests/dbtests.cpp +++ b/src/mongo/dbtests/dbtests.cpp @@ -58,7 +58,6 @@ #include "mongo/util/clock_source_mock.h" #include "mongo/util/quick_exit.h" #include "mongo/util/signal_handlers_synchronous.h" -#include "mongo/util/startup_test.h" #include "mongo/util/text.h" namespace mongo { @@ -214,7 +213,6 @@ int dbtestsMain(int argc, char** argv, char** envp) { AuthorizationManager::get(service)->setAuthEnabled(false); ScriptEngine::setup(); - StartupTest::runTests(); return mongo::dbtests::runDbTests(argc, argv); } diff --git a/src/mongo/s/mongos_options.cpp b/src/mongo/s/mongos_options.cpp index f00243433e8..3a552ddc1b4 100644 --- a/src/mongo/s/mongos_options.cpp +++ b/src/mongo/s/mongos_options.cpp @@ -47,7 +47,6 @@ #include "mongo/util/log.h" #include "mongo/util/net/socket_utils.h" #include "mongo/util/options_parser/startup_options.h" -#include "mongo/util/startup_test.h" #include "mongo/util/str.h" namespace mongo { @@ -71,7 +70,6 @@ bool handlePreValidationMongosOptions(const moe::Environment& params, if (params.count("test") && params["test"].as<bool>() == true) { ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity( ::mongo::logger::LogSeverity::Debug(5)); - StartupTest::runTests(); return false; } diff --git a/src/mongo/shell/SConscript b/src/mongo/shell/SConscript index b357bbcd8c0..9dc9140735b 100644 --- a/src/mongo/shell/SConscript +++ b/src/mongo/shell/SConscript @@ -114,3 +114,34 @@ env.CppUnitTest( 'shell_options_register', ], ) + +env.Library( + target='shell_utils', + source=[ + 'mongo-server.cpp', + 'shell_options.cpp', + 'shell_utils.cpp', + 'shell_utils_extended.cpp', + 'shell_utils_launcher.cpp', + ], + LIBDEPS=[ + 'benchrun', + '$BUILD_DIR/mongo/client/clientdriver_network', + '$BUILD_DIR/mongo/db/mongohasher', + '$BUILD_DIR/mongo/db/traffic_reader', + '$BUILD_DIR/mongo/scripting/scripting', + '$BUILD_DIR/mongo/transport/message_compressor', + '$BUILD_DIR/mongo/util/password', + 'shell_options_storage', + ] +) + +env.CppUnitTest( + target='shell_utils_test', + source=[ + 'shell_utils_test.cpp' + ], + LIBDEPS=[ + 'shell_utils' + ] +) diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp index f7ff703b665..9ee4527f86c 100644 --- a/src/mongo/shell/dbshell.cpp +++ b/src/mongo/shell/dbshell.cpp @@ -69,7 +69,6 @@ #include "mongo/util/scopeguard.h" #include "mongo/util/signal_handlers.h" #include "mongo/util/stacktrace.h" -#include "mongo/util/startup_test.h" #include "mongo/util/str.h" #include "mongo/util/text.h" #include "mongo/util/version.h" @@ -442,165 +441,8 @@ std::string getURIFromArgs(const std::string& arg, return parseDbHost("", "127.0.0.1"); } -static std::string OpSymbols = "~!%^&*-+=|:,<>/?."; - -bool isOpSymbol(char c) { - for (size_t i = 0; i < OpSymbols.size(); i++) - if (OpSymbols[i] == c) - return true; - return false; -} - -bool isUseCmd(const std::string& code) { - std::string cmd = code; - if (cmd.find(" ") > 0) - cmd = cmd.substr(0, cmd.find(" ")); - return cmd == "use"; -} - -/** - * Skip over a quoted string, including quotes escaped with backslash - * - * @param code String - * @param start Starting position within string, always > 0 - * @param quote Quote character (single or double quote) - * @return Position of ending quote, or code.size() if no quote found - */ -size_t skipOverString(const std::string& code, size_t start, char quote) { - size_t pos = start; - while (pos < code.size()) { - pos = code.find(quote, pos); - if (pos == std::string::npos) { - return code.size(); - } - // We want to break if the quote we found is not escaped, but we need to make sure - // that the escaping backslash is not itself escaped. Comparisons of start and pos - // are to keep us from reading beyond the beginning of the quoted string. - // - if (start == pos || code[pos - 1] != '\\' || // previous char was backslash - start == pos - 1 || - code[pos - 2] == '\\' // char before backslash was not another - ) { - break; // The quote we found was not preceded by an unescaped backslash; it is real - } - ++pos; // The quote we found was escaped with backslash, so it doesn't count - } - return pos; -} - -bool isBalanced(const std::string& code) { - if (isUseCmd(code)) - return true; // don't balance "use <dbname>" in case dbname contains special chars - int curlyBrackets = 0; - int squareBrackets = 0; - int parens = 0; - bool danglingOp = false; - - for (size_t i = 0; i < code.size(); i++) { - switch (code[i]) { - case '/': - if (i + 1 < code.size() && code[i + 1] == '/') { - while (i < code.size() && code[i] != '\n') - i++; - } - continue; - case '{': - curlyBrackets++; - break; - case '}': - if (curlyBrackets <= 0) - return true; - curlyBrackets--; - break; - case '[': - squareBrackets++; - break; - case ']': - if (squareBrackets <= 0) - return true; - squareBrackets--; - break; - case '(': - parens++; - break; - case ')': - if (parens <= 0) - return true; - parens--; - break; - case '"': - case '\'': - i = skipOverString(code, i + 1, code[i]); - if (i >= code.size()) { - return true; // Do not let unterminated strings enter multi-line mode - } - break; - case '\\': - if (i + 1 < code.size() && code[i + 1] == '/') - i++; - break; - case '+': - case '-': - if (i + 1 < code.size() && code[i + 1] == code[i]) { - i++; - continue; // postfix op (++/--) can't be a dangling op - } - break; - } - if (i >= code.size()) { - danglingOp = false; - break; - } - if (isOpSymbol(code[i])) - danglingOp = true; - else if (!std::isspace(static_cast<unsigned char>(code[i]))) - danglingOp = false; - } - - return curlyBrackets == 0 && squareBrackets == 0 && parens == 0 && !danglingOp; -} - -struct BalancedTest : public mongo::StartupTest { -public: - void run() { - verify(isBalanced("x = 5")); - verify(isBalanced("function(){}")); - verify(isBalanced("function(){\n}")); - verify(!isBalanced("function(){")); - verify(isBalanced("x = \"{\";")); - verify(isBalanced("// {")); - verify(!isBalanced("// \n {")); - verify(!isBalanced("\"//\" {")); - verify(isBalanced("{x:/x\\//}")); - verify(!isBalanced("{ \\/// }")); - verify(isBalanced("x = 5 + y ")); - verify(!isBalanced("x = ")); - verify(!isBalanced("x = // hello")); - verify(!isBalanced("x = 5 +")); - verify(isBalanced(" x ++")); - verify(isBalanced("-- x")); - verify(!isBalanced("a.")); - verify(!isBalanced("a. ")); - verify(isBalanced("a.b")); - - // SERVER-5809 and related cases -- - verify(isBalanced("a = {s:\"\\\"\"}")); // a = {s:"\""} - verify(isBalanced("db.test.save({s:\"\\\"\"})")); // db.test.save({s:"\""}) - verify(isBalanced("printjson(\" \\\" \")")); // printjson(" \" ") -- SERVER-8554 - verify(isBalanced("var a = \"\\\\\";")); // var a = "\\"; - verify(isBalanced("var a = (\"\\\\\") //\"")); // var a = ("\\") //" - verify(isBalanced("var a = (\"\\\\\") //\\\"")); // var a = ("\\") //\" - verify(isBalanced("var a = (\"\\\\\") //")); // var a = ("\\") // - verify(isBalanced("var a = (\"\\\\\")")); // var a = ("\\") - verify(isBalanced("var a = (\"\\\\\\\"\")")); // var a = ("\\\"") - verify(!isBalanced("var a = (\"\\\\\" //\"")); // var a = ("\\" //" - verify(!isBalanced("var a = (\"\\\\\" //")); // var a = ("\\" // - verify(!isBalanced("var a = (\"\\\\\"")); // var a = ("\\" - } -} balanced_test; - std::string finishCode(std::string code) { - while (!isBalanced(code)) { + while (!shell_utils::isBalanced(code)) { inMultiLine = true; code += "\n"; // cancel multiline if two blank lines are entered @@ -845,8 +687,6 @@ int _main(int argc, char* argv[], char** envp) { if (!mongo::serverGlobalParams.quiet.load()) std::cout << mongoShellVersion(VersionInfoInterface::instance()) << std::endl; - mongo::StartupTest::runTests(); - logger::globalLogManager() ->getNamedDomain("javascriptOutput") ->attachAppender(std::make_unique<ShellConsoleAppender>( diff --git a/src/mongo/shell/shell_utils.cpp b/src/mongo/shell/shell_utils.cpp index c26941d02de..af46190753f 100644 --- a/src/mongo/shell/shell_utils.cpp +++ b/src/mongo/shell/shell_utils.cpp @@ -35,6 +35,7 @@ #include <algorithm> #include <boost/filesystem.hpp> +#include <cctype> #include <memory> #include <set> #include <stdlib.h> @@ -134,8 +135,133 @@ MONGO_REGISTER_SHIM(BenchRunConfig::createConnectionImpl) return connection; } +namespace { + +// helper functions for isBalanced +bool isUseCmd(std::string code) { + size_t first_space = code.find(" "); + if (first_space) + code = code.substr(0, first_space); + return code == "use"; +} + +/** + * Skip over a quoted string, including quotes escaped with backslash + * + * @param code String + * @param start Starting position within string, always > 0 + * @param quote Quote character (single or double quote) + * @return Position of ending quote, or code.size() if no quote found + */ +size_t skipOverString(const std::string& code, size_t start, char quote) { + size_t pos = start; + while (pos < code.size()) { + pos = code.find(quote, pos); + if (pos == std::string::npos) { + return code.size(); + } + // We want to break if the quote we found is not escaped, but we need to make sure + // that the escaping backslash is not itself escaped. Comparisons of start and pos + // are to keep us from reading beyond the beginning of the quoted string. + // + if (start == pos || code[pos - 1] != '\\' || // previous char was backslash + start == pos - 1 || + code[pos - 2] == '\\' // char before backslash was not another + ) { + break; // The quote we found was not preceded by an unescaped backslash; it is real + } + ++pos; // The quote we found was escaped with backslash, so it doesn't count + } + return pos; +} + +bool isOpSymbol(char c) { + static std::string OpSymbols = "~!%^&*-+=|:,<>/?."; + + for (size_t i = 0; i < OpSymbols.size(); i++) + if (OpSymbols[i] == c) + return true; + return false; +} + +} // namespace + namespace shell_utils { + +bool isBalanced(const std::string& code) { + if (isUseCmd(code)) + return true; // don't balance "use <dbname>" in case dbname contains special chars + int curlyBrackets = 0; + int squareBrackets = 0; + int parens = 0; + bool danglingOp = false; + + for (size_t i = 0; i < code.size(); i++) { + switch (code[i]) { + case '/': + if (i + 1 < code.size() && code[i + 1] == '/') { + while (i < code.size() && code[i] != '\n') + i++; + } + continue; + case '{': + curlyBrackets++; + break; + case '}': + if (curlyBrackets <= 0) + return true; + curlyBrackets--; + break; + case '[': + squareBrackets++; + break; + case ']': + if (squareBrackets <= 0) + return true; + squareBrackets--; + break; + case '(': + parens++; + break; + case ')': + if (parens <= 0) + return true; + parens--; + break; + case '"': + case '\'': + i = skipOverString(code, i + 1, code[i]); + if (i >= code.size()) { + return true; // Do not let unterminated strings enter multi-line mode + } + break; + case '\\': + if (i + 1 < code.size() && code[i + 1] == '/') + i++; + break; + case '+': + case '-': + if (i + 1 < code.size() && code[i + 1] == code[i]) { + i++; + continue; // postfix op (++/--) can't be a dangling op + } + break; + } + if (i >= code.size()) { + danglingOp = false; + break; + } + if ("~!%^&*-+=|:,<>/?."_sd.find(code[i]) != std::string::npos) + danglingOp = true; + else if (!std::isspace(code[i])) + danglingOp = false; + } + + return curlyBrackets == 0 && squareBrackets == 0 && parens == 0 && !danglingOp; +} + + std::string dbConnect; static const char* argv0 = 0; diff --git a/src/mongo/shell/shell_utils.h b/src/mongo/shell/shell_utils.h index 7bfaf9ab014..0c856c37ed3 100644 --- a/src/mongo/shell/shell_utils.h +++ b/src/mongo/shell/shell_utils.h @@ -45,6 +45,8 @@ class DBClientBase; namespace shell_utils { +bool isBalanced(const std::string& code); + extern std::string dbConnect; using EnterpriseShellCallback = void(Scope&); diff --git a/src/mongo/shell/shell_utils_test.cpp b/src/mongo/shell/shell_utils_test.cpp new file mode 100644 index 00000000000..64c82f872df --- /dev/null +++ b/src/mongo/shell/shell_utils_test.cpp @@ -0,0 +1,81 @@ +/** + * Copyright (C) 2019-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/shell/shell_utils.h" +#include "mongo/unittest/unittest.h" +#include "mongo/util/assert_util.h" + +namespace mongo { +namespace { + +TEST(ShellUtils, BalancedTest) { + using shell_utils::isBalanced; + struct { + std::string in; + bool isBalanced; + } specs[] = {{"x = 5", true}, + {"function(){}", true}, + {"function(){\n}", true}, + {"function(){", false}, + {R"(x = "{";)", true}, + {"// {", true}, + {"// \n {", false}, + {R"("//" {)", false}, + {R"({x:/x\//})", true}, + {R"({ \/// })", false}, + {"x = 5 + y ", true}, + {"x = ", false}, + {"x = // hello", false}, + {"x = 5 +", false}, + {" x ++", true}, + {"-- x", true}, + {"a.", false}, + {"a. ", false}, + {"a.b", true}, + // SERVER-5809 and related cases -- + {R"(a = {s:"\""})", true}, + {R"(db.test.save({s:"\""}))", true}, + {R"(printjson(" \" "))", true}, //-- SERVER-8554 + {R"(var a = "\\";)", true}, + {R"(var a = ("\\") //")", true}, + {R"(var a = ("\\") //\")", true}, + {R"(var a = ("\\") //\")", true}, + {R"(var a = ("\\") //)", true}, + {R"(var a = ("\\"))", true}, + {R"(var a = ("\\\""))", true}, + {R"(var a = ("\\" //")", false}, + {R"(var a = ("\\" //)", false}, + {R"(var a = ("\\")", false}}; + for (const auto& spec : specs) { + ASSERT_EQUALS(isBalanced(spec.in), spec.isBalanced); + } +} + +} // namespace +} // namespace mongo diff --git a/src/mongo/util/startup_test.cpp b/src/mongo/util/startup_test.cpp deleted file mode 100644 index 8d768bafbd8..00000000000 --- a/src/mongo/util/startup_test.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/util/startup_test.h" - -namespace mongo { -std::vector<StartupTest*>* StartupTest::tests = 0; -bool StartupTest::running = false; - -StartupTest::StartupTest() { - registerTest(this); -} - -StartupTest::~StartupTest() {} - -void StartupTest::registerTest(StartupTest* t) { - if (tests == 0) - tests = new std::vector<StartupTest*>(); - tests->push_back(t); -} - -void StartupTest::runTests() { - running = true; - for (std::vector<StartupTest*>::const_iterator i = tests->begin(); i != tests->end(); i++) { - (*i)->run(); - } - running = false; -} - -} // namespace mongo diff --git a/src/mongo/util/startup_test.h b/src/mongo/util/startup_test.h deleted file mode 100644 index f15fbbad298..00000000000 --- a/src/mongo/util/startup_test.h +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include <vector> - -namespace mongo { - -/* - The idea here is to let all initialization of global variables (classes inheriting from - StartupTest) complete before we run the tests -- otherwise order of initilization being arbitrary - may mess us up. The app's main() function should call runTests(). - - To define a unit test, inherit from this and implement run. instantiate one object for the new - class as a global. - - These tests are ran on *every* startup of mongod, so they have to be very lightweight. But it is - a good quick check for a bad build. -*/ -class StartupTest { -public: - static void runTests(); - - static bool testsInProgress() { - return running; - } - -protected: - StartupTest(); - virtual ~StartupTest(); - -private: - static std::vector<StartupTest*>* tests; - static bool running; - - static void registerTest(StartupTest* t); - - // assert if fails - virtual void run() = 0; -}; - - -} // namespace mongo |