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

Side by Side Diff: base/message_loop/message_pump_libevent_unittest.cc

Issue 2695593009: Use the location where FileDescriptorWatcher is created to track the libevent handlers (Closed)
Patch Set: fix mac. Created 3 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/message_loop/message_pump_libevent.h" 5 #include "base/message_loop/message_pump_libevent.h"
6 6
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 // Test to make sure that we catch calling WatchFileDescriptor off of the 82 // Test to make sure that we catch calling WatchFileDescriptor off of the
83 // wrong thread. 83 // wrong thread.
84 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 84 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
85 // Flaky on Chrome OS and Linux: crbug.com/138845. 85 // Flaky on Chrome OS and Linux: crbug.com/138845.
86 #define MAYBE_TestWatchingFromBadThread DISABLED_TestWatchingFromBadThread 86 #define MAYBE_TestWatchingFromBadThread DISABLED_TestWatchingFromBadThread
87 #else 87 #else
88 #define MAYBE_TestWatchingFromBadThread TestWatchingFromBadThread 88 #define MAYBE_TestWatchingFromBadThread TestWatchingFromBadThread
89 #endif 89 #endif
90 TEST_F(MessagePumpLibeventTest, MAYBE_TestWatchingFromBadThread) { 90 TEST_F(MessagePumpLibeventTest, MAYBE_TestWatchingFromBadThread) {
91 MessagePumpLibevent::FileDescriptorWatcher watcher; 91 MessagePumpLibevent::FileDescriptorWatcher watcher(FROM_HERE);
92 StupidWatcher delegate; 92 StupidWatcher delegate;
93 93
94 ASSERT_DCHECK_DEATH( 94 ASSERT_DCHECK_DEATH(
95 io_loop()->WatchFileDescriptor(STDOUT_FILENO, false, 95 io_loop()->WatchFileDescriptor(STDOUT_FILENO, false,
96 MessageLoopForIO::WATCH_READ, &watcher, 96 MessageLoopForIO::WATCH_READ, &watcher,
97 &delegate)); 97 &delegate));
98 } 98 }
99 99
100 TEST_F(MessagePumpLibeventTest, QuitOutsideOfRun) { 100 TEST_F(MessagePumpLibeventTest, QuitOutsideOfRun) {
101 std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent); 101 std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
(...skipping 28 matching lines...) Expand all
130 void OnFileCanWriteWithoutBlocking(int /* fd */) override { 130 void OnFileCanWriteWithoutBlocking(int /* fd */) override {
131 DCHECK(controller_); 131 DCHECK(controller_);
132 delete controller_; 132 delete controller_;
133 controller_ = NULL; 133 controller_ = NULL;
134 } 134 }
135 }; 135 };
136 136
137 TEST_F(MessagePumpLibeventTest, DeleteWatcher) { 137 TEST_F(MessagePumpLibeventTest, DeleteWatcher) {
138 std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent); 138 std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
139 MessagePumpLibevent::FileDescriptorWatcher* watcher = 139 MessagePumpLibevent::FileDescriptorWatcher* watcher =
140 new MessagePumpLibevent::FileDescriptorWatcher; 140 new MessagePumpLibevent::FileDescriptorWatcher(FROM_HERE);
141 DeleteWatcher delegate(watcher); 141 DeleteWatcher delegate(watcher);
142 pump->WatchFileDescriptor(pipefds_[1], 142 pump->WatchFileDescriptor(pipefds_[1],
143 false, MessagePumpLibevent::WATCH_READ_WRITE, watcher, &delegate); 143 false, MessagePumpLibevent::WATCH_READ_WRITE, watcher, &delegate);
144 144
145 // Spoof a libevent notification. 145 // Spoof a libevent notification.
146 OnLibeventNotification(pump.get(), watcher); 146 OnLibeventNotification(pump.get(), watcher);
147 } 147 }
148 148
149 class StopWatcher : public BaseWatcher { 149 class StopWatcher : public BaseWatcher {
150 public: 150 public:
151 explicit StopWatcher( 151 explicit StopWatcher(
152 MessagePumpLibevent::FileDescriptorWatcher* controller) 152 MessagePumpLibevent::FileDescriptorWatcher* controller)
153 : BaseWatcher(controller) {} 153 : BaseWatcher(controller) {}
154 154
155 ~StopWatcher() override {} 155 ~StopWatcher() override {}
156 156
157 void OnFileCanWriteWithoutBlocking(int /* fd */) override { 157 void OnFileCanWriteWithoutBlocking(int /* fd */) override {
158 controller_->StopWatchingFileDescriptor(); 158 controller_->StopWatchingFileDescriptor();
159 } 159 }
160 }; 160 };
161 161
162 TEST_F(MessagePumpLibeventTest, StopWatcher) { 162 TEST_F(MessagePumpLibeventTest, StopWatcher) {
163 std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent); 163 std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
164 MessagePumpLibevent::FileDescriptorWatcher watcher; 164 MessagePumpLibevent::FileDescriptorWatcher watcher(FROM_HERE);
165 StopWatcher delegate(&watcher); 165 StopWatcher delegate(&watcher);
166 pump->WatchFileDescriptor(pipefds_[1], 166 pump->WatchFileDescriptor(pipefds_[1],
167 false, MessagePumpLibevent::WATCH_READ_WRITE, &watcher, &delegate); 167 false, MessagePumpLibevent::WATCH_READ_WRITE, &watcher, &delegate);
168 168
169 // Spoof a libevent notification. 169 // Spoof a libevent notification.
170 OnLibeventNotification(pump.get(), &watcher); 170 OnLibeventNotification(pump.get(), &watcher);
171 } 171 }
172 172
173 void QuitMessageLoopAndStart(const Closure& quit_closure) { 173 void QuitMessageLoopAndStart(const Closure& quit_closure) {
174 quit_closure.Run(); 174 quit_closure.Run();
(...skipping 14 matching lines...) Expand all
189 ThreadTaskRunnerHandle::Get()->PostTask( 189 ThreadTaskRunnerHandle::Get()->PostTask(
190 FROM_HERE, Bind(&QuitMessageLoopAndStart, runloop.QuitClosure())); 190 FROM_HERE, Bind(&QuitMessageLoopAndStart, runloop.QuitClosure()));
191 runloop.Run(); 191 runloop.Run();
192 } 192 }
193 193
194 void OnFileCanWriteWithoutBlocking(int /* fd */) override {} 194 void OnFileCanWriteWithoutBlocking(int /* fd */) override {}
195 }; 195 };
196 196
197 TEST_F(MessagePumpLibeventTest, NestedPumpWatcher) { 197 TEST_F(MessagePumpLibeventTest, NestedPumpWatcher) {
198 std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent); 198 std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
199 MessagePumpLibevent::FileDescriptorWatcher watcher; 199 MessagePumpLibevent::FileDescriptorWatcher watcher(FROM_HERE);
200 NestedPumpWatcher delegate; 200 NestedPumpWatcher delegate;
201 pump->WatchFileDescriptor(pipefds_[1], 201 pump->WatchFileDescriptor(pipefds_[1],
202 false, MessagePumpLibevent::WATCH_READ, &watcher, &delegate); 202 false, MessagePumpLibevent::WATCH_READ, &watcher, &delegate);
203 203
204 // Spoof a libevent notification. 204 // Spoof a libevent notification.
205 OnLibeventNotification(pump.get(), &watcher); 205 OnLibeventNotification(pump.get(), &watcher);
206 } 206 }
207 207
208 void FatalClosure() { 208 void FatalClosure() {
209 FAIL() << "Reached fatal closure."; 209 FAIL() << "Reached fatal closure.";
(...skipping 27 matching lines...) Expand all
237 237
238 // Tests that MessagePumpLibevent quits immediately when it is quit from 238 // Tests that MessagePumpLibevent quits immediately when it is quit from
239 // libevent's event_base_loop(). 239 // libevent's event_base_loop().
240 TEST_F(MessagePumpLibeventTest, QuitWatcher) { 240 TEST_F(MessagePumpLibeventTest, QuitWatcher) {
241 // Delete the old MessageLoop so that we can manage our own one here. 241 // Delete the old MessageLoop so that we can manage our own one here.
242 ui_loop_.reset(); 242 ui_loop_.reset();
243 243
244 MessagePumpLibevent* pump = new MessagePumpLibevent; // owned by |loop|. 244 MessagePumpLibevent* pump = new MessagePumpLibevent; // owned by |loop|.
245 MessageLoop loop(WrapUnique(pump)); 245 MessageLoop loop(WrapUnique(pump));
246 RunLoop run_loop; 246 RunLoop run_loop;
247 MessagePumpLibevent::FileDescriptorWatcher controller; 247 MessagePumpLibevent::FileDescriptorWatcher controller(FROM_HERE);
248 QuitWatcher delegate(&controller, &run_loop); 248 QuitWatcher delegate(&controller, &run_loop);
249 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC, 249 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC,
250 WaitableEvent::InitialState::NOT_SIGNALED); 250 WaitableEvent::InitialState::NOT_SIGNALED);
251 std::unique_ptr<WaitableEventWatcher> watcher(new WaitableEventWatcher); 251 std::unique_ptr<WaitableEventWatcher> watcher(new WaitableEventWatcher);
252 252
253 // Tell the pump to watch the pipe. 253 // Tell the pump to watch the pipe.
254 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ, 254 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ,
255 &controller, &delegate); 255 &controller, &delegate);
256 256
257 // Make the IO thread wait for |event| before writing to pipefds[1]. 257 // Make the IO thread wait for |event| before writing to pipefds[1].
(...skipping 13 matching lines...) Expand all
271 271
272 // StartWatching can move |watcher| to IO thread. Release on IO thread. 272 // StartWatching can move |watcher| to IO thread. Release on IO thread.
273 io_loop()->task_runner()->PostTask( 273 io_loop()->task_runner()->PostTask(
274 FROM_HERE, 274 FROM_HERE,
275 Bind(&WaitableEventWatcher::StopWatching, Owned(watcher.release()))); 275 Bind(&WaitableEventWatcher::StopWatching, Owned(watcher.release())));
276 } 276 }
277 277
278 } // namespace 278 } // namespace
279 279
280 } // namespace base 280 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_pump_libevent.cc ('k') | chrome/browser/apps/app_shim/unix_domain_socket_acceptor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698