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

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

Issue 2831883003: Do not inherit TaskPriority in TaskTraits. (Closed)
Patch Set: self-review Created 3 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/task_scheduler/task_tracker_posix.h" 5 #include "base/task_scheduler/task_tracker_posix.h"
6 6
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/file_descriptor_watcher_posix.h" 12 #include "base/files/file_descriptor_watcher_posix.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/posix/eintr_wrapper.h" 15 #include "base/posix/eintr_wrapper.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/sequence_token.h" 17 #include "base/sequence_token.h"
18 #include "base/task_scheduler/task.h" 18 #include "base/task_scheduler/task.h"
19 #include "base/task_scheduler/task_traits.h" 19 #include "base/task_scheduler/task_traits.h"
20 #include "base/task_scheduler/test_utils.h"
20 #include "base/time/time.h" 21 #include "base/time/time.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 namespace base { 24 namespace base {
24 namespace internal { 25 namespace internal {
25 26
26 // Verify that TaskTrackerPosix runs a Task it receives. 27 // Verify that TaskTrackerPosix runs a Task it receives.
27 TEST(TaskSchedulerTaskTrackerPosixTest, RunTask) { 28 TEST(TaskSchedulerTaskTrackerPosixTest, RunTask) {
28 MessageLoopForIO message_loop; 29 MessageLoopForIO message_loop;
29 bool did_run = false; 30 bool did_run = false;
30 auto task = MakeUnique<Task>( 31 auto task = MakeUnique<Task>(
31 FROM_HERE, 32 FROM_HERE,
32 Bind([](bool* did_run) { *did_run = true; }, Unretained(&did_run)), 33 Bind([](bool* did_run) { *did_run = true; }, Unretained(&did_run)),
33 TaskTraits(), TimeDelta()); 34 test::CreateTaskTraits(), TimeDelta());
34 TaskTrackerPosix tracker; 35 TaskTrackerPosix tracker;
35 tracker.set_watch_file_descriptor_message_loop(&message_loop); 36 tracker.set_watch_file_descriptor_message_loop(&message_loop);
36 37
37 EXPECT_TRUE(tracker.WillPostTask(task.get())); 38 EXPECT_TRUE(tracker.WillPostTask(task.get()));
38 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create())); 39 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create()));
39 EXPECT_TRUE(did_run); 40 EXPECT_TRUE(did_run);
40 } 41 }
41 42
42 // Verify that FileDescriptorWatcher::WatchReadable() can be called from a task 43 // Verify that FileDescriptorWatcher::WatchReadable() can be called from a task
43 // running in TaskTrackerPosix without a crash. 44 // running in TaskTrackerPosix without a crash.
44 TEST(TaskSchedulerTaskTrackerPosixTest, FileDescriptorWatcher) { 45 TEST(TaskSchedulerTaskTrackerPosixTest, FileDescriptorWatcher) {
45 MessageLoopForIO message_loop; 46 MessageLoopForIO message_loop;
46 int fds[2]; 47 int fds[2];
47 ASSERT_EQ(0, pipe(fds)); 48 ASSERT_EQ(0, pipe(fds));
48 auto task = MakeUnique<Task>( 49 auto task =
49 FROM_HERE, Bind(IgnoreResult(&FileDescriptorWatcher::WatchReadable), 50 MakeUnique<Task>(FROM_HERE,
50 fds[0], Bind(&DoNothing)), 51 Bind(IgnoreResult(&FileDescriptorWatcher::WatchReadable),
51 TaskTraits(), TimeDelta()); 52 fds[0], Bind(&DoNothing)),
53 test::CreateTaskTraits(), TimeDelta());
52 TaskTrackerPosix tracker; 54 TaskTrackerPosix tracker;
53 tracker.set_watch_file_descriptor_message_loop(&message_loop); 55 tracker.set_watch_file_descriptor_message_loop(&message_loop);
54 56
55 EXPECT_TRUE(tracker.WillPostTask(task.get())); 57 EXPECT_TRUE(tracker.WillPostTask(task.get()));
56 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create())); 58 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create()));
57 59
58 // Run the MessageLoop to allow the read watch to be registered and 60 // Run the MessageLoop to allow the read watch to be registered and
59 // unregistered. This prevents a memory leak. 61 // unregistered. This prevents a memory leak.
60 RunLoop().RunUntilIdle(); 62 RunLoop().RunUntilIdle();
61 63
62 EXPECT_EQ(0, IGNORE_EINTR(close(fds[0]))); 64 EXPECT_EQ(0, IGNORE_EINTR(close(fds[0])));
63 EXPECT_EQ(0, IGNORE_EINTR(close(fds[1]))); 65 EXPECT_EQ(0, IGNORE_EINTR(close(fds[1])));
64 } 66 }
65 67
66 } // namespace internal 68 } // namespace internal
67 } // namespace base 69 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698