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

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: Wake up a thread explicitly when a Sequence is added in a PQ. 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 PostTaskNowHelper 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(TaskSchedulerPostTaskNowHelperTest, 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;
31
32 // Post |task|.
33 EXPECT_TRUE(PostTaskNowHelper(std::move(task), sequence, &priority_queue));
34
35 // Expect to find the sequence in the priority queue.
36 EXPECT_EQ(sequence, priority_queue.BeginTransaction()->Peek().sequence);
37
38 // Expect to find |task| alone in |sequence|.
39 EXPECT_EQ(task_raw, sequence->PeekTask());
40 sequence->PopTask();
41 EXPECT_EQ(nullptr, sequence->PeekTask());
42 }
43
44 // Checks that when PostTaskNowHelper is called with a sequence that already
45 // contains a task, the task is added to the sequence but the sequence is not
46 // added to the priority queue.
47 TEST(TaskSchedulerPostTaskNowHelperTest, PostTaskInNonEmptySequence) {
48 std::unique_ptr<Task> task(
49 new Task(FROM_HERE, Bind(&DoNothing), TaskTraits()));
50 const Task* task_raw = task.get();
51 scoped_refptr<Sequence> sequence(new Sequence);
52 PriorityQueue priority_queue;
53
54 // Add an initial task in |sequence|.
55 sequence->PushTask(
56 WrapUnique(new Task(FROM_HERE, Bind(&DoNothing), TaskTraits())));
57
58 // Post |task|.
59 EXPECT_FALSE(PostTaskNowHelper(std::move(task), sequence, &priority_queue));
60
61 // Expect to find the priority queue empty.
62 EXPECT_TRUE(priority_queue.BeginTransaction()->Peek().is_null());
63
64 // Expect to find |task| in |sequence| behind the initial task.
65 EXPECT_NE(task_raw, sequence->PeekTask());
66 sequence->PopTask();
67 EXPECT_EQ(task_raw, sequence->PeekTask());
68 sequence->PopTask();
69 EXPECT_EQ(nullptr, sequence->PeekTask());
70 }
71
72 } // namespace
73 } // namespace internal
74 } // 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