diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/unittest | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/unittest')
| -rw-r--r-- | src/mongo/unittest/bson_test_util.cpp | 1 | ||||
| -rw-r--r-- | src/mongo/unittest/bson_test_util.h | 5 | ||||
| -rw-r--r-- | src/mongo/unittest/thread_assertion_monitor.h | 4 | ||||
| -rw-r--r-- | src/mongo/unittest/unittest.cpp | 57 | ||||
| -rw-r--r-- | src/mongo/unittest/unittest.h | 18 |
5 files changed, 24 insertions, 61 deletions
diff --git a/src/mongo/unittest/bson_test_util.cpp b/src/mongo/unittest/bson_test_util.cpp index 542c902bef1..11f504a8f99 100644 --- a/src/mongo/unittest/bson_test_util.cpp +++ b/src/mongo/unittest/bson_test_util.cpp @@ -29,7 +29,6 @@ #include "mongo/platform/basic.h" -#include "mongo/bson/json.h" #include "mongo/unittest/bson_test_util.h" namespace mongo { diff --git a/src/mongo/unittest/bson_test_util.h b/src/mongo/unittest/bson_test_util.h index ff4b58b5f7b..2e7c928c339 100644 --- a/src/mongo/unittest/bson_test_util.h +++ b/src/mongo/unittest/bson_test_util.h @@ -29,7 +29,6 @@ #pragma once -#include "mongo/bson/json.h" #include "mongo/bson/simple_bsonelement_comparator.h" #include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/unittest/unittest.h" @@ -91,9 +90,5 @@ DECLARE_BSON_CMP_FUNC(BSONElement, GTE); DECLARE_BSON_CMP_FUNC(BSONElement, NE); #undef DECLARE_BSON_CMP_FUNC -// TODO SERVER-87736 this macro is misleading on the v6 .0 branch.We will keep it as "AUTO" for now, -// but there is no 'auto' support on this branch. -#define ASSERT_BSONOBJ_EQ_AUTO(expected, actual) ASSERT_BSONOBJ_EQ(fromjson(expected), actual) - } // namespace unittest } // namespace mongo diff --git a/src/mongo/unittest/thread_assertion_monitor.h b/src/mongo/unittest/thread_assertion_monitor.h index b757be79ef9..b9ce8cba8cb 100644 --- a/src/mongo/unittest/thread_assertion_monitor.h +++ b/src/mongo/unittest/thread_assertion_monitor.h @@ -104,10 +104,8 @@ public: stdx::unique_lock lk(_mu); do { _cv.wait(lk, [&] { return _done || _ex; }); - if (_ex) { - _done = true; + if (_ex) std::rethrow_exception(std::exchange(_ex, nullptr)); - } } while (!_done); } diff --git a/src/mongo/unittest/unittest.cpp b/src/mongo/unittest/unittest.cpp index ef9233554c2..94adc7f1046 100644 --- a/src/mongo/unittest/unittest.cpp +++ b/src/mongo/unittest/unittest.cpp @@ -193,39 +193,27 @@ public: void startCapturingLogMessages(); void stopCapturingLogMessages(); void stopCapturingLogMessagesIfNeeded(); - const synchronized_value<std::vector<std::string>>& getCapturedTextFormatLogMessages() const { - return _capturedLogMessages; - } + const std::vector<std::string>& getCapturedTextFormatLogMessages() const; std::vector<BSONObj> getCapturedBSONFormatLogMessages() const; int64_t countTextFormatLogLinesContaining(const std::string& needle); int64_t countBSONFormatLogLinesIsSubset(const BSONObj& needle); void printCapturedTextFormatLogLines() const; private: - class Listener : public logv2::LogLineListener { - public: - explicit Listener(synchronized_value<std::vector<std::string>>* sv) : _sv(sv) {} - void accept(const std::string& line) override { - (***_sv).push_back(line); - } - - private: - synchronized_value<std::vector<std::string>>* _sv; - }; - bool _isCapturingLogMessages{false}; // Captures Plain Text Log - synchronized_value<std::vector<std::string>> _capturedLogMessages; + std::vector<std::string> _capturedLogMessages; // Captured BSON - synchronized_value<std::vector<std::string>> _capturedBSONLogMessages; + std::vector<std::string> _capturedBSONLogMessages; // Capture Sink for Plain Text - boost::shared_ptr<boost::log::sinks::unlocked_sink<logv2::LogCaptureBackend>> _captureSink; + boost::shared_ptr<boost::log::sinks::synchronous_sink<logv2::LogCaptureBackend>> _captureSink; // Capture Sink for BSON - boost::shared_ptr<boost::log::sinks::unlocked_sink<logv2::LogCaptureBackend>> _captureBSONSink; + boost::shared_ptr<boost::log::sinks::synchronous_sink<logv2::LogCaptureBackend>> + _captureBSONSink; }; static CaptureLogs* getCaptureLogs() { @@ -260,18 +248,16 @@ namespace { void CaptureLogs::startCapturingLogMessages() { invariant(!_isCapturingLogMessages); - (**_capturedLogMessages).clear(); - (**_capturedBSONLogMessages).clear(); + _capturedLogMessages.clear(); + _capturedBSONLogMessages.clear(); if (!_captureSink) { - _captureSink = logv2::LogCaptureBackend::create( - std::make_unique<Listener>(&_capturedLogMessages), true); + _captureSink = logv2::LogCaptureBackend::create(_capturedLogMessages, true); _captureSink->set_filter( logv2::AllLogsFilter(logv2::LogManager::global().getGlobalDomain())); _captureSink->set_formatter(logv2::PlainFormatter()); - _captureBSONSink = logv2::LogCaptureBackend::create( - std::make_unique<Listener>(&_capturedBSONLogMessages), false); + _captureBSONSink = logv2::LogCaptureBackend::create(_capturedBSONLogMessages, false); _captureBSONSink->set_filter( logv2::AllLogsFilter(logv2::LogManager::global().getGlobalDomain())); @@ -297,11 +283,14 @@ void CaptureLogs::stopCapturingLogMessagesIfNeeded() { } } +const std::vector<std::string>& CaptureLogs::getCapturedTextFormatLogMessages() const { + return _capturedLogMessages; +} + std::vector<BSONObj> CaptureLogs::getCapturedBSONFormatLogMessages() const { std::vector<BSONObj> objs; - auto logLinesLockGuard = *_capturedBSONLogMessages; - std::transform(logLinesLockGuard->cbegin(), - logLinesLockGuard->cend(), + std::transform(_capturedBSONLogMessages.cbegin(), + _capturedBSONLogMessages.cend(), std::back_inserter(objs), [](const std::string& str) { return BSONObj(str.c_str()); }); return objs; @@ -309,8 +298,7 @@ std::vector<BSONObj> CaptureLogs::getCapturedBSONFormatLogMessages() const { void CaptureLogs::printCapturedTextFormatLogLines() const { LOGV2(23054, "****************************** Captured Lines (start) *****************************"); - auto logLinesLockGuard = *getCapturedTextFormatLogMessages(); - for (const auto& line : *logLinesLockGuard) { + for (const auto& line : getCapturedTextFormatLogMessages()) { LOGV2(23055, "{line}", "line"_attr = line); } LOGV2(23056, @@ -318,10 +306,9 @@ void CaptureLogs::printCapturedTextFormatLogLines() const { } int64_t CaptureLogs::countTextFormatLogLinesContaining(const std::string& needle) { - auto msgs = *getCapturedTextFormatLogMessages(); - return std::count_if(msgs->begin(), msgs->end(), [&](const std::string& s) { - return stringContains(s, needle); - }); + const auto& msgs = getCapturedTextFormatLogMessages(); + return std::count_if( + msgs.begin(), msgs.end(), [&](const std::string& s) { return stringContains(s, needle); }); } bool isSubset(BSONObj haystack, BSONObj needle) { @@ -373,8 +360,8 @@ void Test::startCapturingLogMessages() { void Test::stopCapturingLogMessages() { getCaptureLogs()->stopCapturingLogMessages(); } -std::vector<std::string> Test::getCapturedTextFormatLogMessages() const { - return getCaptureLogs()->getCapturedTextFormatLogMessages().get(); +const std::vector<std::string>& Test::getCapturedTextFormatLogMessages() const { + return getCaptureLogs()->getCapturedTextFormatLogMessages(); } std::vector<BSONObj> Test::getCapturedBSONFormatLogMessages() const { return getCaptureLogs()->getCapturedBSONFormatLogMessages(); diff --git a/src/mongo/unittest/unittest.h b/src/mongo/unittest/unittest.h index 8e82eb5e06b..514a8e7d8d9 100644 --- a/src/mongo/unittest/unittest.h +++ b/src/mongo/unittest/unittest.h @@ -53,7 +53,6 @@ #include "mongo/unittest/bson_test_util.h" #include "mongo/util/assert_util.h" #include "mongo/util/str.h" -#include "mongo/util/synchronized_value.h" /** * Fail unconditionally, reporting the given message. @@ -152,21 +151,6 @@ ASSERT_THROWS_WITH_CHECK(EXPRESSION, EXCEPTION_TYPE, ([](const EXCEPTION_TYPE&) {})) /** - * Verify that the evaluation of "EXPRESSION" does not throw any exceptions. - * - * If "EXPRESSION" throws an exception the test is considered a failure and further evaluation - * halts. - */ -#define ASSERT_DOES_NOT_THROW(EXPRESSION) \ - try { \ - EXPRESSION; \ - } catch (const AssertionException& e) { \ - str::stream err; \ - err << "Threw an exception incorrectly: " << e.toString(); \ - FAIL(err); \ - } - -/** * Behaves like ASSERT_THROWS, above, but also fails if calling what() on the thrown exception * does not return a string equal to EXPECTED_WHAT. */ @@ -665,7 +649,7 @@ protected: * Gets a vector of strings, one log line per string, captured since * the last call to startCapturingLogMessages() in this test. */ - std::vector<std::string> getCapturedTextFormatLogMessages() const; + const std::vector<std::string>& getCapturedTextFormatLogMessages() const; std::vector<BSONObj> getCapturedBSONFormatLogMessages() const; /** |
