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

Unified Diff: base/task_scheduler/scheduler_worker_pool_impl_unittest.cc

Issue 2501763002: Add Thread Standby Policy SchedulerWorkerPoolImpl (Closed)
Patch Set: Rebase to edc7bea Created 4 years, 1 month 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
Index: base/task_scheduler/scheduler_worker_pool_impl_unittest.cc
diff --git a/base/task_scheduler/scheduler_worker_pool_impl_unittest.cc b/base/task_scheduler/scheduler_worker_pool_impl_unittest.cc
index 3b9393e19abcd7e5d484da54dd9d7f826cf86f93..9983cad5c166bb1f11ff5e79d7a1c0802482812c 100644
--- a/base/task_scheduler/scheduler_worker_pool_impl_unittest.cc
+++ b/base/task_scheduler/scheduler_worker_pool_impl_unittest.cc
@@ -59,6 +59,7 @@ constexpr TimeDelta kExtraTimeToWaitForDetach =
TimeDelta::FromSeconds(1);
using IORestriction = SchedulerWorkerPoolParams::IORestriction;
+using StandbyThreadPolicy = SchedulerWorkerPoolParams::StandbyThreadPolicy;
class TaskSchedulerWorkerPoolImplTest
: public testing::TestWithParam<test::ExecutionMode> {
@@ -84,9 +85,9 @@ class TaskSchedulerWorkerPoolImplTest
delayed_task_manager_ =
base::MakeUnique<DelayedTaskManager>(service_thread_.task_runner());
worker_pool_ = SchedulerWorkerPoolImpl::Create(
- SchedulerWorkerPoolParams("TestWorkerPool", ThreadPriority::NORMAL,
- IORestriction::ALLOWED, num_workers,
- suggested_reclaim_time),
+ SchedulerWorkerPoolParams(
+ "TestWorkerPool", ThreadPriority::NORMAL, IORestriction::ALLOWED,
+ StandbyThreadPolicy::LAZY, num_workers, suggested_reclaim_time),
Bind(&TaskSchedulerWorkerPoolImplTest::ReEnqueueSequenceCallback,
Unretained(this)),
&task_tracker_, delayed_task_manager_.get());
@@ -473,9 +474,9 @@ TEST_P(TaskSchedulerWorkerPoolImplIORestrictionTest, IORestriction) {
make_scoped_refptr(new TestSimpleTaskRunner));
auto worker_pool = SchedulerWorkerPoolImpl::Create(
- SchedulerWorkerPoolParams("TestWorkerPoolWithParam",
- ThreadPriority::NORMAL, GetParam(), 1U,
- TimeDelta::Max()),
+ SchedulerWorkerPoolParams(
+ "TestWorkerPoolWithParam", ThreadPriority::NORMAL, GetParam(),
+ StandbyThreadPolicy::LAZY, 1U, TimeDelta::Max()),
Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker,
&delayed_task_manager);
ASSERT_TRUE(worker_pool);
@@ -825,5 +826,36 @@ TEST_F(TaskSchedulerWorkerPoolHistogramTest, NumTasksBeforeDetach) {
EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(10));
}
+TEST(TaskSchedulerWorkerPoolStandbyPolicyTest, InitLazy) {
+ TaskTracker task_tracker;
+ DelayedTaskManager delayed_task_manager(
+ make_scoped_refptr(new TestSimpleTaskRunner));
+ auto worker_pool = SchedulerWorkerPoolImpl::Create(
+ SchedulerWorkerPoolParams("LazyPolicyWorkerPool", ThreadPriority::NORMAL,
+ IORestriction::DISALLOWED,
+ StandbyThreadPolicy::LAZY, 8U,
+ TimeDelta::Max()),
+ Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker,
+ &delayed_task_manager);
+ ASSERT_TRUE(worker_pool);
+ EXPECT_EQ(0U, worker_pool->NumberOfAliveWorkersForTesting());
+ worker_pool->JoinForTesting();
+}
+
+TEST(TaskSchedulerWorkerPoolStandbyPolicyTest, InitOne) {
+ TaskTracker task_tracker;
+ DelayedTaskManager delayed_task_manager(
+ make_scoped_refptr(new TestSimpleTaskRunner));
+ auto worker_pool = SchedulerWorkerPoolImpl::Create(
+ SchedulerWorkerPoolParams("LazyPolicyWorkerPool", ThreadPriority::NORMAL,
+ IORestriction::DISALLOWED,
+ StandbyThreadPolicy::ONE, 8U, TimeDelta::Max()),
+ Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker,
+ &delayed_task_manager);
+ ASSERT_TRUE(worker_pool);
+ EXPECT_EQ(1U, worker_pool->NumberOfAliveWorkersForTesting());
+ worker_pool->JoinForTesting();
+}
+
} // namespace internal
} // namespace base
« no previous file with comments | « base/task_scheduler/scheduler_worker_pool_impl.cc ('k') | base/task_scheduler/scheduler_worker_pool_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698