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

Side by Side Diff: base/task_scheduler/scheduler_thread_pool_impl_unittest.cc

Issue 2032603002: Migrate WaitableEvent to enum-based constructor in base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WEvent_enums
Patch Set: undo incorrect template change Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/task_scheduler/scheduler_thread_pool_impl.h" 5 #include "base/task_scheduler/scheduler_thread_pool_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <unordered_set> 10 #include <unordered_set>
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 216
217 // Wait until all worker threads are idle to be sure that no task accesses 217 // Wait until all worker threads are idle to be sure that no task accesses
218 // its TestTaskFactory after |thread_posting_tasks| is destroyed. 218 // its TestTaskFactory after |thread_posting_tasks| is destroyed.
219 thread_pool_->WaitForAllWorkerThreadsIdleForTesting(); 219 thread_pool_->WaitForAllWorkerThreadsIdleForTesting();
220 } 220 }
221 221
222 TEST_P(TaskSchedulerThreadPoolImplTest, PostTasksWithOneAvailableThread) { 222 TEST_P(TaskSchedulerThreadPoolImplTest, PostTasksWithOneAvailableThread) {
223 // Post blocking tasks to keep all threads busy except one until |event| is 223 // Post blocking tasks to keep all threads busy except one until |event| is
224 // signaled. Use different factories so that tasks are added to different 224 // signaled. Use different factories so that tasks are added to different
225 // sequences and can run simultaneously when the execution mode is SEQUENCED. 225 // sequences and can run simultaneously when the execution mode is SEQUENCED.
226 WaitableEvent event(true, false); 226 WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL,
227 WaitableEvent::InitialState::NOT_SIGNALED);
227 std::vector<std::unique_ptr<test::TestTaskFactory>> blocked_task_factories; 228 std::vector<std::unique_ptr<test::TestTaskFactory>> blocked_task_factories;
228 for (size_t i = 0; i < (kNumThreadsInThreadPool - 1); ++i) { 229 for (size_t i = 0; i < (kNumThreadsInThreadPool - 1); ++i) {
229 blocked_task_factories.push_back(WrapUnique(new test::TestTaskFactory( 230 blocked_task_factories.push_back(WrapUnique(new test::TestTaskFactory(
230 thread_pool_->CreateTaskRunnerWithTraits(TaskTraits(), GetParam()), 231 thread_pool_->CreateTaskRunnerWithTraits(TaskTraits(), GetParam()),
231 GetParam()))); 232 GetParam())));
232 EXPECT_TRUE(blocked_task_factories.back()->PostTask( 233 EXPECT_TRUE(blocked_task_factories.back()->PostTask(
233 PostNestedTask::NO, Bind(&WaitableEvent::Wait, Unretained(&event)))); 234 PostNestedTask::NO, Bind(&WaitableEvent::Wait, Unretained(&event))));
234 blocked_task_factories.back()->WaitForAllTasksToRun(); 235 blocked_task_factories.back()->WaitForAllTasksToRun();
235 } 236 }
236 237
(...skipping 12 matching lines...) Expand all
249 // Wait until all worker threads are idle to be sure that no task accesses 250 // Wait until all worker threads are idle to be sure that no task accesses
250 // its TestTaskFactory after it is destroyed. 251 // its TestTaskFactory after it is destroyed.
251 thread_pool_->WaitForAllWorkerThreadsIdleForTesting(); 252 thread_pool_->WaitForAllWorkerThreadsIdleForTesting();
252 } 253 }
253 254
254 TEST_P(TaskSchedulerThreadPoolImplTest, Saturate) { 255 TEST_P(TaskSchedulerThreadPoolImplTest, Saturate) {
255 // Verify that it is possible to have |kNumThreadsInThreadPool| 256 // Verify that it is possible to have |kNumThreadsInThreadPool|
256 // tasks/sequences running simultaneously. Use different factories so that the 257 // tasks/sequences running simultaneously. Use different factories so that the
257 // blocking tasks are added to different sequences and can run simultaneously 258 // blocking tasks are added to different sequences and can run simultaneously
258 // when the execution mode is SEQUENCED. 259 // when the execution mode is SEQUENCED.
259 WaitableEvent event(true, false); 260 WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL,
261 WaitableEvent::InitialState::NOT_SIGNALED);
260 std::vector<std::unique_ptr<test::TestTaskFactory>> factories; 262 std::vector<std::unique_ptr<test::TestTaskFactory>> factories;
261 for (size_t i = 0; i < kNumThreadsInThreadPool; ++i) { 263 for (size_t i = 0; i < kNumThreadsInThreadPool; ++i) {
262 factories.push_back(WrapUnique(new test::TestTaskFactory( 264 factories.push_back(WrapUnique(new test::TestTaskFactory(
263 thread_pool_->CreateTaskRunnerWithTraits(TaskTraits(), GetParam()), 265 thread_pool_->CreateTaskRunnerWithTraits(TaskTraits(), GetParam()),
264 GetParam()))); 266 GetParam())));
265 EXPECT_TRUE(factories.back()->PostTask( 267 EXPECT_TRUE(factories.back()->PostTask(
266 PostNestedTask::NO, Bind(&WaitableEvent::Wait, Unretained(&event)))); 268 PostNestedTask::NO, Bind(&WaitableEvent::Wait, Unretained(&event))));
267 factories.back()->WaitForAllTasksToRun(); 269 factories.back()->WaitForAllTasksToRun();
268 } 270 }
269 271
(...skipping 12 matching lines...) Expand all
282 task_tracker_.Shutdown(); 284 task_tracker_.Shutdown();
283 EXPECT_FALSE(task_runner->PostTask(FROM_HERE, Bind(&ShouldNotRunCallback))); 285 EXPECT_FALSE(task_runner->PostTask(FROM_HERE, Bind(&ShouldNotRunCallback)));
284 } 286 }
285 287
286 // Verify that a Task posted with a delay is added to the DelayedTaskManager and 288 // Verify that a Task posted with a delay is added to the DelayedTaskManager and
287 // doesn't run before its delay expires. 289 // doesn't run before its delay expires.
288 TEST_P(TaskSchedulerThreadPoolImplTest, PostDelayedTask) { 290 TEST_P(TaskSchedulerThreadPoolImplTest, PostDelayedTask) {
289 EXPECT_TRUE(delayed_task_manager_.GetDelayedRunTime().is_null()); 291 EXPECT_TRUE(delayed_task_manager_.GetDelayedRunTime().is_null());
290 292
291 // Post a delayed task. 293 // Post a delayed task.
292 WaitableEvent task_ran(true, false); 294 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL,
295 WaitableEvent::InitialState::NOT_SIGNALED);
293 EXPECT_TRUE(thread_pool_->CreateTaskRunnerWithTraits(TaskTraits(), GetParam()) 296 EXPECT_TRUE(thread_pool_->CreateTaskRunnerWithTraits(TaskTraits(), GetParam())
294 ->PostDelayedTask(FROM_HERE, Bind(&WaitableEvent::Signal, 297 ->PostDelayedTask(FROM_HERE, Bind(&WaitableEvent::Signal,
295 Unretained(&task_ran)), 298 Unretained(&task_ran)),
296 TimeDelta::FromSeconds(10))); 299 TimeDelta::FromSeconds(10)));
297 300
298 // The task should have been added to the DelayedTaskManager. 301 // The task should have been added to the DelayedTaskManager.
299 EXPECT_FALSE(delayed_task_manager_.GetDelayedRunTime().is_null()); 302 EXPECT_FALSE(delayed_task_manager_.GetDelayedRunTime().is_null());
300 303
301 // The task shouldn't run. 304 // The task shouldn't run.
302 EXPECT_FALSE(task_ran.IsSignaled()); 305 EXPECT_FALSE(task_ran.IsSignaled());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 TEST_P(TaskSchedulerThreadPoolImplIORestrictionTest, IORestriction) { 361 TEST_P(TaskSchedulerThreadPoolImplIORestrictionTest, IORestriction) {
359 TaskTracker task_tracker; 362 TaskTracker task_tracker;
360 DelayedTaskManager delayed_task_manager(Bind(&DoNothing)); 363 DelayedTaskManager delayed_task_manager(Bind(&DoNothing));
361 364
362 auto thread_pool = SchedulerThreadPoolImpl::Create( 365 auto thread_pool = SchedulerThreadPoolImpl::Create(
363 "TestThreadPoolWithParam", ThreadPriority::NORMAL, 1U, GetParam(), 366 "TestThreadPoolWithParam", ThreadPriority::NORMAL, 1U, GetParam(),
364 Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker, 367 Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker,
365 &delayed_task_manager); 368 &delayed_task_manager);
366 ASSERT_TRUE(thread_pool); 369 ASSERT_TRUE(thread_pool);
367 370
368 WaitableEvent task_ran(true, false); 371 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL,
372 WaitableEvent::InitialState::NOT_SIGNALED);
369 thread_pool->CreateTaskRunnerWithTraits(TaskTraits(), ExecutionMode::PARALLEL) 373 thread_pool->CreateTaskRunnerWithTraits(TaskTraits(), ExecutionMode::PARALLEL)
370 ->PostTask(FROM_HERE, Bind(&ExpectIORestriction, GetParam(), &task_ran)); 374 ->PostTask(FROM_HERE, Bind(&ExpectIORestriction, GetParam(), &task_ran));
371 task_ran.Wait(); 375 task_ran.Wait();
372 376
373 thread_pool->JoinForTesting(); 377 thread_pool->JoinForTesting();
374 } 378 }
375 379
376 INSTANTIATE_TEST_CASE_P(IOAllowed, 380 INSTANTIATE_TEST_CASE_P(IOAllowed,
377 TaskSchedulerThreadPoolImplIORestrictionTest, 381 TaskSchedulerThreadPoolImplIORestrictionTest,
378 ::testing::Values(IORestriction::ALLOWED)); 382 ::testing::Values(IORestriction::ALLOWED));
379 INSTANTIATE_TEST_CASE_P(IODisallowed, 383 INSTANTIATE_TEST_CASE_P(IODisallowed,
380 TaskSchedulerThreadPoolImplIORestrictionTest, 384 TaskSchedulerThreadPoolImplIORestrictionTest,
381 ::testing::Values(IORestriction::DISALLOWED)); 385 ::testing::Values(IORestriction::DISALLOWED));
382 386
383 } // namespace internal 387 } // namespace internal
384 } // namespace base 388 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_thread_pool_impl.cc ('k') | base/task_scheduler/scheduler_worker_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698