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

Unified Diff: base/trace_event/memory_dump_manager_unittest.cc

Issue 2778313002: [memory-infra] Move periodic timer to dump thread
Patch Set: nits. Created 3 years, 9 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 | « no previous file | base/trace_event/memory_dump_scheduler.h » ('j') | 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 3a2992b6f92d687d72d8c0902501ca041ad99389..1d17f351456b0a5aa448a3a21a67417b9c7a09b7 100644
--- a/base/trace_event/memory_dump_manager_unittest.cc
+++ b/base/trace_event/memory_dump_manager_unittest.cc
@@ -274,6 +274,10 @@ class MemoryDumpManagerTest : public testing::Test {
void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); }
+ void DisablePeriodicTimerForTesting(bool disable) {
+ MemoryDumpScheduler::GetInstance()->DisablePeriodicTimerForTesting(disable);
+ }
+
bool IsPeriodicDumpingEnabled() const {
return MemoryDumpScheduler::GetInstance()
->IsPeriodicTimerRunningForTesting();
@@ -952,6 +956,9 @@ TEST_F(MemoryDumpManagerTest, TraceConfigExpectationsWhenIsCoordinator) {
MemoryDumpManagerDelegateForTesting& delegate = *delegate_;
ON_CALL(delegate, RequestGlobalMemoryDump(_, _)).WillByDefault(Return());
+ // Disable timer to avoid post tasks.
+ DisablePeriodicTimerForTesting(true);
+
// Enabling memory-infra with the legacy TraceConfig (category filter) in
// a coordinator process should enable periodic dumps.
EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
@@ -976,11 +983,14 @@ TEST_F(MemoryDumpManagerTest, TraceConfigExpectationsWhenIsCoordinator) {
EXPECT_FALSE(IsPeriodicDumpingEnabled());
DisableTracing();
+ DisablePeriodicTimerForTesting(false);
+
// Enabling memory-infra with the new (JSON) TraceConfig in a coordinator
// process with a fully defined trigger config should cause periodic dumps to
// be performed in the correct order.
RunLoop run_loop;
auto quit_closure = run_loop.QuitClosure();
+ auto run_loop_task_runner = ThreadTaskRunnerHandle::Get();
const int kHeavyDumpRate = 5;
const int kLightDumpPeriodMs = 1;
@@ -994,9 +1004,10 @@ TEST_F(MemoryDumpManagerTest, TraceConfigExpectationsWhenIsCoordinator) {
EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _))
.Times(kHeavyDumpRate - 2);
EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _))
- .WillOnce(Invoke([quit_closure](const MemoryDumpRequestArgs& args,
- const MemoryDumpCallback& callback) {
- ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure);
+ .WillOnce(Invoke([quit_closure, run_loop_task_runner](
+ const MemoryDumpRequestArgs& args,
+ const MemoryDumpCallback& callback) {
+ run_loop_task_runner->PostTask(FROM_HERE, quit_closure);
}));
// Swallow all the final spurious calls until tracing gets disabled.
@@ -1245,14 +1256,16 @@ TEST_F(MemoryDumpManagerTest, TestBackgroundTracingSetup) {
RunLoop run_loop;
auto quit_closure = run_loop.QuitClosure();
+ auto run_loop_task_runner = ThreadTaskRunnerHandle::Get();
testing::InSequence sequence;
EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _))
.Times(5);
EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _))
- .WillOnce(Invoke([quit_closure](const MemoryDumpRequestArgs& args,
- const MemoryDumpCallback& callback) {
- ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure);
+ .WillOnce(Invoke([quit_closure, run_loop_task_runner](
+ const MemoryDumpRequestArgs& args,
+ const MemoryDumpCallback& callback) {
+ run_loop_task_runner->PostTask(FROM_HERE, quit_closure);
}));
EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(AnyNumber());
« no previous file with comments | « no previous file | base/trace_event/memory_dump_scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698