summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorauto-revert-processor <dev-prod-dag@mongodb.com>2021-12-22 07:03:15 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-22 07:29:02 +0000
commit60f32a2e789ad4fcab61d80ffd57ba930f088117 (patch)
tree4f1f2346c07af47274e0500d054fa9420fce43c2
parent1701a682db7a8548755d7fa8d50b8d712c17dadf (diff)
downloadmongo-60f32a2e789ad4fcab61d80ffd57ba930f088117.tar.gz
Revert "SERVER-61732 Prevent threads spawned outside ThreadContextTest from updating test counters"
This reverts commit ff375f0ae47b960f46a8606d0f5fd6558230709b.
-rw-r--r--src/mongo/util/thread_context_test.cpp54
1 files changed, 12 insertions, 42 deletions
diff --git a/src/mongo/util/thread_context_test.cpp b/src/mongo/util/thread_context_test.cpp
index a7f17ce2393..99e94fb7837 100644
--- a/src/mongo/util/thread_context_test.cpp
+++ b/src/mongo/util/thread_context_test.cpp
@@ -27,11 +27,8 @@
* it in the license file.
*/
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
-
#include "mongo/platform/basic.h"
-#include "mongo/logv2/log.h"
#include "mongo/util/thread_context.h"
#include <boost/optional.hpp>
@@ -76,37 +73,23 @@ synchronized_value gCounters{Counters{0, 0, 0}};
class TestDecoration {
public:
TestDecoration() {
- invariant(!ThreadContext::get());
-
- if (newInstancesEnabled) {
- // Thread name is not available here, so log the ID for diagnostic purposes.
- LOGV2_INFO(6173200,
- "Incrementing creation counter",
- "threadId"_attr = ProcessId::getCurrentThreadId());
- ++gCounters->created;
- }
- }
+ ASSERT(!ThreadContext::get())
+ << "ThreadContext decorations should be created before the ThreadContext is set";
+
+ ++gCounters->created;
+ };
~TestDecoration() {
- if (newInstancesEnabled) {
- // Thread name might not be available here, so log the ID for diagnostic purposes.
- LOGV2_INFO(6173201,
- "Incrementing destruction counter(s)",
- "threadId"_attr = ProcessId::getCurrentThreadId());
- ++gCounters->destroyed;
-
- if (ThreadContext::get()) {
- // We should only be able to reference a ThreadContext in our destructor if our
- // lifetime was extended to be off thread.
- ++gCounters->destroyedOffThread;
- }
+ ++gCounters->destroyed;
+
+ if (ThreadContext::get()) {
+ // We should only be able to reference a ThreadContext in our destructor if our
+ // lifetime was extended to be off thread.
+ ++gCounters->destroyedOffThread;
}
}
-
- static thread_local bool newInstancesEnabled;
};
-thread_local bool TestDecoration::newInstancesEnabled = false;
const auto getThreadTestDecoration = ThreadContext::declareDecoration<TestDecoration>();
class ThreadContextTest : public unittest::Test {
@@ -115,13 +98,11 @@ public:
ThreadContext::get(); // Ensure a ThreadContext for the main thread.
_monitor.emplace();
*gCounters = {0, 0, 0};
- TestDecoration::newInstancesEnabled = true;
}
void tearDown() override {
_monitor->notifyDone();
_monitor.reset();
- TestDecoration::newInstancesEnabled = false;
auto endCount = gCounters.get();
ASSERT_EQ(endCount.created, endCount.destroyed);
ASSERT_GTE(endCount.destroyed, endCount.destroyedOffThread);
@@ -136,12 +117,6 @@ public:
ASSERT(context);
ASSERT(context->isAlive());
- // Log the thread ID for diagnostic purposes, so it can be associated with
- // the thread name and cross-referenced with other logging statements here.
- LOGV2_INFO(6173202,
- "Retrieving thread context",
- "threadId"_attr = ProcessId::getCurrentThreadId());
-
return context;
}
@@ -158,12 +133,7 @@ public:
*/
template <typename F>
void launchAndJoinThread(F&& f) {
- _monitor
- ->spawn([&] {
- TestDecoration::newInstancesEnabled = true;
- std::forward<F>(f)();
- })
- .join();
+ _monitor->spawn(std::forward<F>(f)).join();
}
boost::optional<unittest::ThreadAssertionMonitor> _monitor;