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

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: CR robliao #35 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
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
gab 2016/04/14 16:11:35 Can we also test PostTaskHelper?
fdoray 2016/04/14 18:41:12 Done.
23 // Checks that when PostTaskWithSequenceHelper is called with an empty sequence,
24 // the task is added to the sequence and the sequence is added to the priority
25 // queue.
26 TEST(TaskSchedulerPostTaskWithSequenceHelperTest, PostTaskInEmptySequence) {
27 std::unique_ptr<Task> task(
28 new Task(FROM_HERE, Bind(&DoNothing), TaskTraits()));
29 const Task* task_raw = task.get();
30 scoped_refptr<Sequence> sequence(new Sequence);
31 PriorityQueue priority_queue;
32
33 // Post |task|.
34 EXPECT_TRUE(
35 PostTaskWithSequenceHelper(std::move(task), sequence, &priority_queue));
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 PostTaskWithSequenceHelper is called with a sequence that
47 // already contains a task, the task is added to the sequence but the sequence
48 // is not added to the priority queue.
49 TEST(TaskSchedulerPostTaskWithSequenceHelperTest, 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;
55
56 // Add an initial task in |sequence|.
57 sequence->PushTask(
58 WrapUnique(new Task(FROM_HERE, Bind(&DoNothing), TaskTraits())));
59
60 // Post |task|.
61 EXPECT_FALSE(
62 PostTaskWithSequenceHelper(std::move(task), sequence, &priority_queue));
63
64 // Expect to find the priority queue empty.
65 EXPECT_TRUE(priority_queue.BeginTransaction()->Peek().is_null());
66
67 // Expect to find |task| in |sequence| behind the initial task.
68 EXPECT_NE(task_raw, sequence->PeekTask());
69 sequence->PopTask();
70 EXPECT_EQ(task_raw, sequence->PeekTask());
71 sequence->PopTask();
72 EXPECT_EQ(nullptr, sequence->PeekTask());
73 }
74
75 } // namespace
76 } // namespace internal
77 } // namespace base
OLDNEW
« base/task_scheduler/scheduler_thread_pool.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