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

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

Issue 1708773002: TaskScheduler [7] SchedulerThreadPool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s_5_worker_thread
Patch Set: self review 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 unified diff | Download patch
« base/task_scheduler/utils.cc ('K') | « base/task_scheduler/utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/utils.h"
6
7 #include <memory>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/task_scheduler/priority_queue.h"
14 #include "base/task_scheduler/sequence.h"
15 #include "base/task_scheduler/task.h"
16 #include "base/task_scheduler/task_tracker.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace base {
20 namespace internal {
21 namespace {
22
23 // Checks that when PostTaskHelper is called with an empty sequence, the task
24 // is added to the sequence and the sequence is added to the priority queue.
25 TEST(TaskSchedulerPostTaskHelperTest, PostTaskInEmptySequence) {
26 std::unique_ptr<Task> task(
27 new Task(FROM_HERE, Bind(&DoNothing), TaskTraits()));
28 const Task* task_raw = task.get();
29 scoped_refptr<Sequence> sequence(new Sequence);
30 PriorityQueue priority_queue(Bind(&DoNothing));
31 TaskTracker task_tracker;
32
33 // Post |task|.
34 EXPECT_TRUE(PostTaskHelper(std::move(task), sequence, &priority_queue,
35 &task_tracker));
36
37 // Expect to find the sequence in the priority queue.
38 EXPECT_EQ(sequence, priority_queue.BeginTransaction()->Peek().sequence);
39
40 // Expect to find |task| alone in |sequence|.
41 EXPECT_EQ(task_raw, sequence->PeekTask());
42 sequence->PopTask();
43 EXPECT_EQ(nullptr, sequence->PeekTask());
44 }
45
46 // Checks that when PostTaskHelper is called with a sequence that already
47 // contains a task, the task is added to the sequence but the sequence is not
48 // added to the priority queue.
49 TEST(TaskSchedulerPostTaskHelperTest, PostTaskInNonEmptySequence) {
50 std::unique_ptr<Task> task(
51 new Task(FROM_HERE, Bind(&DoNothing), TaskTraits()));
52 const Task* task_raw = task.get();
53 scoped_refptr<Sequence> sequence(new Sequence);
54 PriorityQueue priority_queue(Bind(&DoNothing));
55 TaskTracker task_tracker;
56
57 // Add an initial task in |sequence|.
58 sequence->PushTask(
59 WrapUnique(new Task(FROM_HERE, Bind(&DoNothing), TaskTraits())));
60
61 // Post |task|.
62 EXPECT_TRUE(PostTaskHelper(std::move(task), sequence, &priority_queue,
63 &task_tracker));
64
65 // Expect to find the priority queue empty.
66 EXPECT_TRUE(priority_queue.BeginTransaction()->Peek().is_null());
67
68 // Expect to find |task| in |sequence| behind the initial task.
69 EXPECT_NE(task_raw, sequence->PeekTask());
70 sequence->PopTask();
71 EXPECT_EQ(task_raw, sequence->PeekTask());
72 sequence->PopTask();
73 EXPECT_EQ(nullptr, sequence->PeekTask());
74 }
75
76 } // namespace
77 } // namespace internal
78 } // namespace base
OLDNEW
« base/task_scheduler/utils.cc ('K') | « base/task_scheduler/utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698