| OLD | NEW |
| 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/task_scheduler_impl.h" | 5 #include "base/task_scheduler/task_scheduler_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 const test::ExecutionMode execution_modes[] = { | 169 const test::ExecutionMode execution_modes[] = { |
| 170 test::ExecutionMode::PARALLEL, test::ExecutionMode::SEQUENCED, | 170 test::ExecutionMode::PARALLEL, test::ExecutionMode::SEQUENCED, |
| 171 test::ExecutionMode::SINGLE_THREADED}; | 171 test::ExecutionMode::SINGLE_THREADED}; |
| 172 | 172 |
| 173 for (test::ExecutionMode execution_mode : execution_modes) { | 173 for (test::ExecutionMode execution_mode : execution_modes) { |
| 174 for (size_t priority_index = static_cast<size_t>(TaskPriority::LOWEST); | 174 for (size_t priority_index = static_cast<size_t>(TaskPriority::LOWEST); |
| 175 priority_index <= static_cast<size_t>(TaskPriority::HIGHEST); | 175 priority_index <= static_cast<size_t>(TaskPriority::HIGHEST); |
| 176 ++priority_index) { | 176 ++priority_index) { |
| 177 const TaskPriority priority = static_cast<TaskPriority>(priority_index); | 177 const TaskPriority priority = static_cast<TaskPriority>(priority_index); |
| 178 params.push_back(TraitsExecutionModePair( | 178 params.push_back(TraitsExecutionModePair({priority}, execution_mode)); |
| 179 TaskTraits().WithPriority(priority), execution_mode)); | 179 params.push_back(TraitsExecutionModePair({MayBlock()}, execution_mode)); |
| 180 params.push_back(TraitsExecutionModePair( | |
| 181 TaskTraits().WithPriority(priority).MayBlock(), execution_mode)); | |
| 182 } | 180 } |
| 183 } | 181 } |
| 184 | 182 |
| 185 return params; | 183 return params; |
| 186 } | 184 } |
| 187 | 185 |
| 188 class TaskSchedulerImplTest | 186 class TaskSchedulerImplTest |
| 189 : public testing::TestWithParam<TraitsExecutionModePair> { | 187 : public testing::TestWithParam<TraitsExecutionModePair> { |
| 190 protected: | 188 protected: |
| 191 TaskSchedulerImplTest() : scheduler_("Test") {} | 189 TaskSchedulerImplTest() : scheduler_("Test") {} |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 | 359 |
| 362 for (const auto& thread : threads_posting_tasks) { | 360 for (const auto& thread : threads_posting_tasks) { |
| 363 thread->WaitForAllTasksToRun(); | 361 thread->WaitForAllTasksToRun(); |
| 364 thread->Join(); | 362 thread->Join(); |
| 365 } | 363 } |
| 366 } | 364 } |
| 367 | 365 |
| 368 TEST_F(TaskSchedulerImplTest, GetMaxConcurrentTasksWithTraitsDeprecated) { | 366 TEST_F(TaskSchedulerImplTest, GetMaxConcurrentTasksWithTraitsDeprecated) { |
| 369 StartTaskScheduler(); | 367 StartTaskScheduler(); |
| 370 EXPECT_EQ(1, scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( | 368 EXPECT_EQ(1, scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( |
| 371 TaskTraits().WithPriority(TaskPriority::BACKGROUND))); | 369 {TaskPriority::BACKGROUND})); |
| 372 EXPECT_EQ( | 370 EXPECT_EQ(3, scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( |
| 373 3, scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( | 371 {MayBlock(), TaskPriority::BACKGROUND})); |
| 374 TaskTraits().WithPriority(TaskPriority::BACKGROUND).MayBlock())); | |
| 375 EXPECT_EQ(4, scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( | 372 EXPECT_EQ(4, scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( |
| 376 TaskTraits().WithPriority(TaskPriority::USER_VISIBLE))); | 373 {TaskPriority::USER_VISIBLE})); |
| 377 EXPECT_EQ( | 374 EXPECT_EQ(12, scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( |
| 378 12, | 375 {MayBlock(), TaskPriority::USER_VISIBLE})); |
| 379 scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( | |
| 380 TaskTraits().WithPriority(TaskPriority::USER_VISIBLE).MayBlock())); | |
| 381 EXPECT_EQ(4, scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( | 376 EXPECT_EQ(4, scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( |
| 382 TaskTraits().WithPriority(TaskPriority::USER_BLOCKING))); | 377 {TaskPriority::USER_BLOCKING})); |
| 383 EXPECT_EQ( | 378 EXPECT_EQ(12, scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( |
| 384 12, | 379 {MayBlock(), TaskPriority::USER_BLOCKING})); |
| 385 scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( | |
| 386 TaskTraits().WithPriority(TaskPriority::USER_BLOCKING).MayBlock())); | |
| 387 } | 380 } |
| 388 | 381 |
| 389 // Verify that the RunsTasksOnCurrentThread() method of a SequencedTaskRunner | 382 // Verify that the RunsTasksOnCurrentThread() method of a SequencedTaskRunner |
| 390 // returns false when called from a task that isn't part of the sequence. | 383 // returns false when called from a task that isn't part of the sequence. |
| 391 TEST_F(TaskSchedulerImplTest, SequencedRunsTasksOnCurrentThread) { | 384 TEST_F(TaskSchedulerImplTest, SequencedRunsTasksOnCurrentThread) { |
| 392 StartTaskScheduler(); | 385 StartTaskScheduler(); |
| 393 auto single_thread_task_runner = | 386 auto single_thread_task_runner = |
| 394 scheduler_.CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); | 387 scheduler_.CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); |
| 395 auto sequenced_task_runner = | 388 auto sequenced_task_runner = |
| 396 scheduler_.CreateSequencedTaskRunnerWithTraits(TaskTraits()); | 389 scheduler_.CreateSequencedTaskRunnerWithTraits(TaskTraits()); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 #if defined(OS_POSIX) | 474 #if defined(OS_POSIX) |
| 482 | 475 |
| 483 TEST_F(TaskSchedulerImplTest, FileDescriptorWatcherNoOpsAfterShutdown) { | 476 TEST_F(TaskSchedulerImplTest, FileDescriptorWatcherNoOpsAfterShutdown) { |
| 484 StartTaskScheduler(); | 477 StartTaskScheduler(); |
| 485 | 478 |
| 486 int pipes[2]; | 479 int pipes[2]; |
| 487 ASSERT_EQ(0, pipe(pipes)); | 480 ASSERT_EQ(0, pipe(pipes)); |
| 488 | 481 |
| 489 scoped_refptr<TaskRunner> blocking_task_runner = | 482 scoped_refptr<TaskRunner> blocking_task_runner = |
| 490 scheduler_.CreateSequencedTaskRunnerWithTraits( | 483 scheduler_.CreateSequencedTaskRunnerWithTraits( |
| 491 TaskTraits().WithShutdownBehavior( | 484 {TaskShutdownBehavior::BLOCK_SHUTDOWN}); |
| 492 TaskShutdownBehavior::BLOCK_SHUTDOWN)); | |
| 493 blocking_task_runner->PostTask( | 485 blocking_task_runner->PostTask( |
| 494 FROM_HERE, | 486 FROM_HERE, |
| 495 BindOnce( | 487 BindOnce( |
| 496 [](int read_fd) { | 488 [](int read_fd) { |
| 497 std::unique_ptr<FileDescriptorWatcher::Controller> controller = | 489 std::unique_ptr<FileDescriptorWatcher::Controller> controller = |
| 498 FileDescriptorWatcher::WatchReadable( | 490 FileDescriptorWatcher::WatchReadable( |
| 499 read_fd, BindRepeating([]() { NOTREACHED(); })); | 491 read_fd, BindRepeating([]() { NOTREACHED(); })); |
| 500 | 492 |
| 501 // This test is for components that intentionally leak their | 493 // This test is for components that intentionally leak their |
| 502 // watchers at shutdown. We can't clean |controller| up because its | 494 // watchers at shutdown. We can't clean |controller| up because its |
| (...skipping 18 matching lines...) Expand all Loading... |
| 521 // Give a chance for the file watcher to fire before closing the handles. | 513 // Give a chance for the file watcher to fire before closing the handles. |
| 522 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 514 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 523 | 515 |
| 524 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[0]))); | 516 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[0]))); |
| 525 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[1]))); | 517 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[1]))); |
| 526 } | 518 } |
| 527 #endif // defined(OS_POSIX) | 519 #endif // defined(OS_POSIX) |
| 528 | 520 |
| 529 } // namespace internal | 521 } // namespace internal |
| 530 } // namespace base | 522 } // namespace base |
| OLD | NEW |