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

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

Issue 2816653003: Do not take a MessageLoopForIO in the constructor of TaskTrackerPosix. (Closed)
Patch Set: rebase 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
« no previous file with comments | « base/task_scheduler/task_tracker_posix.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
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
(...skipping 13 matching lines...) Expand all
24 namespace internal { 24 namespace internal {
25 25
26 // Verify that TaskTrackerPosix runs a Task it receives. 26 // Verify that TaskTrackerPosix runs a Task it receives.
27 TEST(TaskSchedulerTaskTrackerPosixTest, RunTask) { 27 TEST(TaskSchedulerTaskTrackerPosixTest, RunTask) {
28 MessageLoopForIO message_loop; 28 MessageLoopForIO message_loop;
29 bool did_run = false; 29 bool did_run = false;
30 auto task = MakeUnique<Task>( 30 auto task = MakeUnique<Task>(
31 FROM_HERE, 31 FROM_HERE,
32 Bind([](bool* did_run) { *did_run = true; }, Unretained(&did_run)), 32 Bind([](bool* did_run) { *did_run = true; }, Unretained(&did_run)),
33 TaskTraits(), TimeDelta()); 33 TaskTraits(), TimeDelta());
34 TaskTrackerPosix tracker(&message_loop); 34 TaskTrackerPosix tracker;
35 tracker.set_watch_file_descriptor_message_loop(&message_loop);
35 36
36 EXPECT_TRUE(tracker.WillPostTask(task.get())); 37 EXPECT_TRUE(tracker.WillPostTask(task.get()));
37 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create())); 38 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create()));
38 EXPECT_TRUE(did_run); 39 EXPECT_TRUE(did_run);
39 } 40 }
40 41
41 // Verify that FileDescriptorWatcher::WatchReadable() can be called from a task 42 // Verify that FileDescriptorWatcher::WatchReadable() can be called from a task
42 // running in TaskTrackerPosix without a crash. 43 // running in TaskTrackerPosix without a crash.
43 TEST(TaskSchedulerTaskTrackerPosixTest, FileDescriptorWatcher) { 44 TEST(TaskSchedulerTaskTrackerPosixTest, FileDescriptorWatcher) {
44 MessageLoopForIO message_loop; 45 MessageLoopForIO message_loop;
45 int fds[2]; 46 int fds[2];
46 ASSERT_EQ(0, pipe(fds)); 47 ASSERT_EQ(0, pipe(fds));
47 auto task = MakeUnique<Task>( 48 auto task = MakeUnique<Task>(
48 FROM_HERE, Bind(IgnoreResult(&FileDescriptorWatcher::WatchReadable), 49 FROM_HERE, Bind(IgnoreResult(&FileDescriptorWatcher::WatchReadable),
49 fds[0], Bind(&DoNothing)), 50 fds[0], Bind(&DoNothing)),
50 TaskTraits(), TimeDelta()); 51 TaskTraits(), TimeDelta());
51 TaskTrackerPosix tracker(&message_loop); 52 TaskTrackerPosix tracker;
53 tracker.set_watch_file_descriptor_message_loop(&message_loop);
52 54
53 EXPECT_TRUE(tracker.WillPostTask(task.get())); 55 EXPECT_TRUE(tracker.WillPostTask(task.get()));
54 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create())); 56 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create()));
55 57
56 // Run the MessageLoop to allow the read watch to be registered and 58 // Run the MessageLoop to allow the read watch to be registered and
57 // unregistered. This prevents a memory leak. 59 // unregistered. This prevents a memory leak.
58 RunLoop().RunUntilIdle(); 60 RunLoop().RunUntilIdle();
59 61
60 EXPECT_EQ(0, IGNORE_EINTR(close(fds[0]))); 62 EXPECT_EQ(0, IGNORE_EINTR(close(fds[0])));
61 EXPECT_EQ(0, IGNORE_EINTR(close(fds[1]))); 63 EXPECT_EQ(0, IGNORE_EINTR(close(fds[1])));
62 } 64 }
63 65
64 } // namespace internal 66 } // namespace internal
65 } // namespace base 67 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_tracker_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698