Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3339)

Unified Diff: base/trace_event/memory_dump_manager_unittest.cc

Issue 1884573002: Fix race condition when dump providers invoked within destroyed state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/memory_dump_manager_unittest.cc
diff --git a/base/trace_event/memory_dump_manager_unittest.cc b/base/trace_event/memory_dump_manager_unittest.cc
index 2461e616790476de6ab95ef14a8ddc2695b21d01..0de5a48a23d1b397dd7596177d49a8d6ad7698c8 100644
--- a/base/trace_event/memory_dump_manager_unittest.cc
+++ b/base/trace_event/memory_dump_manager_unittest.cc
@@ -117,7 +117,17 @@ class MockMemoryDumpProvider : public MemoryDumpProvider {
MOCK_METHOD2(OnMemoryDump,
bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd));
- MockMemoryDumpProvider() : enable_mock_destructor(false) {}
+ MockMemoryDumpProvider() : enable_mock_destructor(false) {
+ ON_CALL(*this, OnMemoryDump(_, _))
+ .WillByDefault(Invoke([](const MemoryDumpArgs&,
+ ProcessMemoryDump* pmd) -> bool {
+ // |session_state| should not be null under any circumstances when
+ // invoking a memory dump. The problem might arise in race conditions
+ // like crbug.com/600570 .
+ EXPECT_TRUE(pmd->session_state().get() != nullptr);
+ return true;
+ }));
+ }
~MockMemoryDumpProvider() override {
if (enable_mock_destructor)
Destructor();
@@ -938,8 +948,14 @@ TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) {
base::WaitableEvent tracing_disabled_event(false, false);
InitializeMemoryDumpManager(false /* is_coordinator */);
- MockMemoryDumpProvider mdp;
- RegisterDumpProvider(&mdp);
+ std::unique_ptr<Thread> mdp_thread(new Thread("test thread"));
+ mdp_thread->Start();
+
+ // Create both same-thread MDP and another MDP with dedicated thread
+ MockMemoryDumpProvider mdp1;
+ RegisterDumpProvider(&mdp1);
+ MockMemoryDumpProvider mdp2;
+ RegisterDumpProvider(&mdp2, mdp_thread->task_runner(), kDefaultOptions);
EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _))
@@ -949,6 +965,11 @@ TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) {
delegate_->CreateProcessDump(args, callback);
}));
+ // If tracing is disabled for current session CreateProcessDump() should NOT
+ // request dumps from providers. Real-world regression: crbug.com/600570 .
+ EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0);
+ EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0);
+
last_callback_success_ = true;
RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
MemoryDumpLevelOfDetail::DETAILED);
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698