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

Unified Diff: base/task_scheduler/scheduler_thread_pool_unittest.cc

Issue 1876363004: TaskScheduler [11] Support ExecutionMode::SINGLE_THREADED. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@8_delayed
Patch Set: all post tasks go through SchedulerThreadPool 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
Index: base/task_scheduler/scheduler_thread_pool_unittest.cc
diff --git a/base/task_scheduler/scheduler_thread_pool_unittest.cc b/base/task_scheduler/scheduler_thread_pool_unittest.cc
index 7e1ec5c2cb1195864e6e812072b13f7a540ad4e6..bfb10c138b131a9e3890b6f66d38951ddeb3994e 100644
--- a/base/task_scheduler/scheduler_thread_pool_unittest.cc
+++ b/base/task_scheduler/scheduler_thread_pool_unittest.cc
@@ -25,6 +25,7 @@
#include "base/task_scheduler/task_tracker.h"
#include "base/threading/platform_thread.h"
#include "base/threading/simple_thread.h"
+#include "base/threading/thread_checker_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -79,7 +80,11 @@ class TaskFactory {
: cv_(&lock_),
task_runner_(thread_pool->CreateTaskRunnerWithTraits(TaskTraits(),
execution_mode)),
- execution_mode_(execution_mode) {}
+ execution_mode_(execution_mode) {
+ // Detach |thread_checker_| from the current thread. It will be attached to
+ // the first thread that calls ThreadCheckerImpl::CalledOnValidThread().
+ thread_checker_.DetachFromThread();
+ }
// Posts a task through |task_runner_|. If |post_nested_task| is true, the
// task will post a new task when it runs. If |event| is set, the task will
@@ -119,11 +124,15 @@ class TaskFactory {
{
AutoLock auto_lock(lock_);
- if (execution_mode_ == ExecutionMode::SEQUENCED &&
+ if ((execution_mode_ == ExecutionMode::SEQUENCED ||
+ execution_mode_ == ExecutionMode::SINGLE_THREADED) &&
task_index != ran_tasks_.size()) {
- ADD_FAILURE() << "A SEQUENCED task didn't run in the expected order.";
+ ADD_FAILURE() << "A task didn't run in the expected order.";
}
+ if (execution_mode_ == ExecutionMode::SINGLE_THREADED)
+ EXPECT_TRUE(thread_checker_.CalledOnValidThread());
+
if (ran_tasks_.find(task_index) != ran_tasks_.end())
ADD_FAILURE() << "A task ran more than once.";
ran_tasks_.insert(task_index);
@@ -153,6 +162,10 @@ class TaskFactory {
// Indexes of tasks that ran.
std::unordered_set<size_t> ran_tasks_;
+ // Used to verify that all tasks run on the same thread when |execution_mode_|
+ // is SINGLE_THREADED.
+ ThreadCheckerImpl thread_checker_;
+
DISALLOW_COPY_AND_ASSIGN(TaskFactory);
};
@@ -331,6 +344,9 @@ INSTANTIATE_TEST_CASE_P(Parallel,
INSTANTIATE_TEST_CASE_P(Sequenced,
TaskSchedulerThreadPoolTest,
::testing::Values(ExecutionMode::SEQUENCED));
+INSTANTIATE_TEST_CASE_P(SingleThreaded,
+ TaskSchedulerThreadPoolTest,
+ ::testing::Values(ExecutionMode::SINGLE_THREADED));
} // namespace
} // namespace internal

Powered by Google App Engine
This is Rietveld 408576698