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

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

Issue 1701343003: TaskScheduler [13] TaskSchedulerImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s_6_threadpool
Patch Set: initial patch for review Created 4 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/task_scheduler/task_scheduler_impl.h"
6
7 #include <stddef.h>
8
9 #include <vector>
10
11 #include "base/bind.h"
12 #include "base/callback.h"
13 #include "base/macros.h"
14 #include "base/task_scheduler/task_traits.h"
15 #include "base/task_scheduler/test_task_factory.h"
16 #include "base/threading/platform_thread.h"
17 #include "base/threading/thread.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace base {
21 namespace internal {
22
23 namespace {
24
25 const size_t kNumTasksPerTest = 150;
26
27 struct TaskSchedulerImplTestParams {
28 TaskSchedulerImplTestParams(const TaskTraits& traits,
29 ExecutionMode execution_mode)
30 : traits(traits), execution_mode(execution_mode) {}
31
32 const TaskTraits traits;
33 const ExecutionMode execution_mode;
34 };
35
36 class TaskSchedulerImplTest
37 : public testing::TestWithParam<TaskSchedulerImplTestParams> {
38 protected:
39 TaskSchedulerImplTest() = default;
40
41 void SetUp() override {
42 scheduler_ = TaskSchedulerImpl::Create();
43 EXPECT_TRUE(scheduler_);
44 }
45
46 void TearDown() override { scheduler_->JoinForTesting(); }
47
48 std::unique_ptr<TaskSchedulerImpl> scheduler_;
gab 2016/04/27 19:15:28 If we get rid of Create() this can just be a plain
fdoray 2016/04/28 18:36:32 Done.
49
50 private:
51 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImplTest);
52 };
53
54 std::vector<TaskSchedulerImplTestParams> GetTaskSchedulerImplTestParams() {
gab 2016/04/27 19:15:29 // Returns a vector with a TaskSchedulerImplTestPa
fdoray 2016/04/28 18:36:32 Done.
55 std::vector<TaskSchedulerImplTestParams> params;
56
57 // TODO(fdoray): Add ExecutionMode::SINGLE_THREADED once it's supported.
gab 2016/04/27 19:15:29 Isn't this based on top of the CL that makes it su
fdoray 2016/04/28 18:36:32 It is now :)
58 ExecutionMode execution_modes[] = {ExecutionMode::PARALLEL,
59 ExecutionMode::SEQUENCED};
60
61 for (size_t execution_mode_index = 0;
gab 2016/04/27 19:15:28 for (ExecutionMode execution_mode : execution_mode
fdoray 2016/04/28 18:36:32 Done.
62 execution_mode_index < arraysize(execution_modes);
63 ++execution_mode_index) {
64 for (size_t priority_index = static_cast<size_t>(TaskPriority::LOWEST);
65 priority_index <= static_cast<size_t>(TaskPriority::HIGHEST);
66 ++priority_index) {
67 const TaskPriority priority = static_cast<TaskPriority>(priority_index);
68 params.push_back(
69 TaskSchedulerImplTestParams(TaskTraits().WithPriority(priority),
70 execution_modes[execution_mode_index]));
71 params.push_back(TaskSchedulerImplTestParams(
72 TaskTraits().WithPriority(priority).WithFileIO(),
73 execution_modes[execution_mode_index]));
74 }
75 }
76
77 return params;
78 }
79
80 void ExpectThreadPriority(ThreadPriority priority) {
81 EXPECT_EQ(priority, PlatformThread::GetCurrentThreadPriority());
82 }
83
84 } // namespace
85
86 TEST_P(TaskSchedulerImplTest, PostTasks) {
87 test::TestTaskFactory factory(
88 scheduler_->CreateTaskRunnerWithTraits(GetParam().traits,
89 GetParam().execution_mode),
90 GetParam().execution_mode);
91 EXPECT_FALSE(factory.task_runner()->RunsTasksOnCurrentThread());
92
93 for (size_t i = 0; i < kNumTasksPerTest; ++i) {
94 factory.PostTask(
95 test::TestTaskFactory::PostNestedTask::NO,
96 Bind(&ExpectThreadPriority,
gab 2016/04/27 19:15:29 Also add AssertIOAllowed expectations (to verify W
fdoray 2016/04/28 18:36:32 Done.
97 GetParam().traits.priority() == TaskPriority::BACKGROUND
98 ? ThreadPriority::BACKGROUND
99 : ThreadPriority::NORMAL));
100 }
101
102 factory.WaitForAllTasksToRun();
103 }
104
gab 2016/04/27 19:15:28 One of the key part of TaskSchedulerImpl (well I g
fdoray 2016/04/28 18:36:32 Done.
105 INSTANTIATE_TEST_CASE_P(TaskTraitsExecutionModeCombinations,
106 TaskSchedulerImplTest,
107 ::testing::ValuesIn(GetTaskSchedulerImplTestParams()));
gab 2016/04/27 19:15:28 Whatttt!!!?!?! This doesn't have to be statically
fdoray 2016/04/28 18:36:32 The name of a test is TaskTraitsExecutionModeCombi
gab 2016/04/28 19:29:02 Cool :-), I guess if one of them was flaky the fla
108
109 } // namespace internal
110 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698