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

Side by Side Diff: chrome/browser/metrics/thread_watcher_unittest.cc

Issue 6602004: Trying changes to see the perfomance impact on Mac.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/metrics/thread_watcher.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #if 0
6
7 #include "base/basictypes.h" 5 #include "base/basictypes.h"
8 #include "base/logging.h" 6 #include "base/logging.h"
9 #include "base/message_loop.h" 7 #include "base/message_loop.h"
10 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
11 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
12 #include "base/synchronization/condition_variable.h" 10 #include "base/synchronization/condition_variable.h"
13 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
14 #include "base/threading/platform_thread.h" 12 #include "base/threading/platform_thread.h"
15 #include "base/time.h" 13 #include "base/time.h"
14 #include "build/build_config.h"
16 #include "chrome/browser/metrics/thread_watcher.h" 15 #include "chrome/browser/metrics/thread_watcher.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 #include "testing/platform_test.h" 17 #include "testing/platform_test.h"
19 18
20 using base::TimeDelta; 19 using base::TimeDelta;
21 using base::TimeTicks; 20 using base::TimeTicks;
22 21
23 enum State { 22 enum State {
24 INITIALIZED, // Created ThreadWatch object. 23 INITIALIZED, // Created ThreadWatch object.
25 ACTIVATED, // Thread watching activated. 24 ACTIVATED, // Thread watching activated.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 check_response_state_ = FAILED; 138 check_response_state_ = FAILED;
140 } 139 }
141 } 140 }
142 // Broadcast to indicate we have checked responsiveness of the thread that 141 // Broadcast to indicate we have checked responsiveness of the thread that
143 // is watched. 142 // is watched.
144 state_changed_.Broadcast(); 143 state_changed_.Broadcast();
145 return responsive; 144 return responsive;
146 } 145 }
147 146
148 void VeryLongMethod(TimeDelta wait_time) { 147 void VeryLongMethod(TimeDelta wait_time) {
149 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::WATCHDOG)); 148 DCHECK(!WatchDogThread::CurrentlyOnWatchDogThread());
150 TimeTicks end_time = TimeTicks::Now() + wait_time; 149 TimeTicks end_time = TimeTicks::Now() + wait_time;
151 { 150 {
152 base::AutoLock auto_lock(custom_lock_); 151 base::AutoLock auto_lock(custom_lock_);
153 while (wait_state_ != STOPPED_WAITING && TimeTicks::Now() < end_time) { 152 while (wait_state_ != STOPPED_WAITING && TimeTicks::Now() < end_time) {
154 TimeDelta state_change_wait_time = end_time - TimeTicks::Now(); 153 TimeDelta state_change_wait_time = end_time - TimeTicks::Now();
155 // LOG(INFO) << "In VeryLongMethod: thread_name_: " << thread_name_ << 154 // LOG(INFO) << "In VeryLongMethod: thread_name_: " << thread_name_ <<
156 // " wait:" << state_change_wait_time.InMilliseconds() << 155 // " wait:" << state_change_wait_time.InMilliseconds() <<
157 // " wait_state_:" << wait_state_; 156 // " wait_state_:" << wait_state_;
158 state_changed_.TimedWait(state_change_wait_time); 157 state_changed_.TimedWait(state_change_wait_time);
159 } 158 }
160 } 159 }
161 } 160 }
162 161
163 State WaitForStateChange(const TimeDelta& wait_time, State expected_state) { 162 State WaitForStateChange(const TimeDelta& wait_time, State expected_state) {
164 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::WATCHDOG)); 163 DCHECK(!WatchDogThread::CurrentlyOnWatchDogThread());
165 UpdateWaitState(STARTED_WAITING); 164 UpdateWaitState(STARTED_WAITING);
166 165
167 State exit_state; 166 State exit_state;
168 // Keep the thread that is running the tests waiting until ThreadWatcher 167 // Keep the thread that is running the tests waiting until ThreadWatcher
169 // object's state changes to the expected_state or until wait_time elapses. 168 // object's state changes to the expected_state or until wait_time elapses.
170 for (int i = 0; i < 3; ++i) { 169 for (int i = 0; i < 3; ++i) {
171 TimeTicks end_time = TimeTicks::Now() + wait_time; 170 TimeTicks end_time = TimeTicks::Now() + wait_time;
172 { 171 {
173 base::AutoLock auto_lock(custom_lock_); 172 base::AutoLock auto_lock(custom_lock_);
174 while (thread_watcher_state_ != expected_state && 173 while (thread_watcher_state_ != expected_state &&
(...skipping 14 matching lines...) Expand all
189 } 188 }
190 // LOG(INFO) << "In WaitForStateChange: thread_name_: " << thread_name_ << 189 // LOG(INFO) << "In WaitForStateChange: thread_name_: " << thread_name_ <<
191 // " expected_state: " << expected_state << 190 // " expected_state: " << expected_state <<
192 // " exit_state:" << exit_state; 191 // " exit_state:" << exit_state;
193 UpdateWaitState(STOPPED_WAITING); 192 UpdateWaitState(STOPPED_WAITING);
194 return exit_state; 193 return exit_state;
195 } 194 }
196 195
197 CheckResponseState WaitForCheckResponse(const TimeDelta& wait_time, 196 CheckResponseState WaitForCheckResponse(const TimeDelta& wait_time,
198 CheckResponseState expected_state) { 197 CheckResponseState expected_state) {
199 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::WATCHDOG)); 198 DCHECK(!WatchDogThread::CurrentlyOnWatchDogThread());
200 UpdateWaitState(STARTED_WAITING); 199 UpdateWaitState(STARTED_WAITING);
201 200
202 CheckResponseState exit_state; 201 CheckResponseState exit_state;
203 // Keep the thread that is running the tests waiting until ThreadWatcher 202 // Keep the thread that is running the tests waiting until ThreadWatcher
204 // object's check_response_state_ changes to the expected_state or until 203 // object's check_response_state_ changes to the expected_state or until
205 // wait_time elapses. 204 // wait_time elapses.
206 for (int i = 0; i < 3; ++i) { 205 for (int i = 0; i < 3; ++i) {
207 TimeTicks end_time = TimeTicks::Now() + wait_time; 206 TimeTicks end_time = TimeTicks::Now() + wait_time;
208 { 207 {
209 base::AutoLock auto_lock(custom_lock_); 208 base::AutoLock auto_lock(custom_lock_);
(...skipping 28 matching lines...) Expand all
238 static const TimeDelta kSleepTime; 237 static const TimeDelta kSleepTime;
239 static const TimeDelta kUnresponsiveTime; 238 static const TimeDelta kUnresponsiveTime;
240 static const BrowserThread::ID io_thread_id; 239 static const BrowserThread::ID io_thread_id;
241 static const std::string io_thread_name; 240 static const std::string io_thread_name;
242 static const BrowserThread::ID webkit_thread_id; 241 static const BrowserThread::ID webkit_thread_id;
243 static const std::string webkit_thread_name; 242 static const std::string webkit_thread_name;
244 CustomThreadWatcher* io_watcher_; 243 CustomThreadWatcher* io_watcher_;
245 CustomThreadWatcher* webkit_watcher_; 244 CustomThreadWatcher* webkit_watcher_;
246 245
247 ThreadWatcherTest() { 246 ThreadWatcherTest() {
248 }
249
250 protected:
251 virtual void SetUp() {
252 webkit_thread_.reset(new BrowserThread(BrowserThread::WEBKIT)); 247 webkit_thread_.reset(new BrowserThread(BrowserThread::WEBKIT));
253 io_thread_.reset(new BrowserThread(BrowserThread::IO)); 248 io_thread_.reset(new BrowserThread(BrowserThread::IO));
254 watchdog_thread_.reset(new BrowserThread(BrowserThread::WATCHDOG)); 249 watchdog_thread_.reset(new WatchDogThread());
255 webkit_thread_->Start(); 250 webkit_thread_->Start();
256 io_thread_->Start(); 251 io_thread_->Start();
257 watchdog_thread_->Start(); 252 watchdog_thread_->Start();
258 253
259 // Setup the registry for thread watchers. 254 // Setup the registry for thread watchers.
260 thread_watcher_list_ = new ThreadWatcherList(); 255 thread_watcher_list_ = new ThreadWatcherList();
261 256
262 // Create thread watcher object for the IO thread. 257 // Create thread watcher object for the IO thread.
263 io_watcher_ = new CustomThreadWatcher(io_thread_id, io_thread_name, 258 io_watcher_ = new CustomThreadWatcher(io_thread_id, io_thread_name,
264 kSleepTime, kUnresponsiveTime); 259 kSleepTime, kUnresponsiveTime);
265 260
266 // Create thread watcher object for the WEBKIT thread. 261 // Create thread watcher object for the WEBKIT thread.
267 webkit_watcher_ = new CustomThreadWatcher( 262 webkit_watcher_ = new CustomThreadWatcher(
268 webkit_thread_id, webkit_thread_name, kSleepTime, kUnresponsiveTime); 263 webkit_thread_id, webkit_thread_name, kSleepTime, kUnresponsiveTime);
269 } 264 }
270 265
271 virtual void TearDown() { 266 ~ThreadWatcherTest() {
272 // io_thread_->Stop(); 267 // io_thread_->Stop();
273 // webkit_thread_->Stop(); 268 // webkit_thread_->Stop();
274 // watchdog_thread_->Stop(); 269 // watchdog_thread_->Stop();
275 io_thread_.reset(); 270 io_thread_.reset();
276 webkit_thread_.reset(); 271 webkit_thread_.reset();
277 watchdog_thread_.reset(); 272 watchdog_thread_.reset();
278 delete thread_watcher_list_; 273 delete thread_watcher_list_;
279 } 274 }
280 275
281 private: 276 private:
282 scoped_ptr<BrowserThread> webkit_thread_; 277 scoped_ptr<BrowserThread> webkit_thread_;
283 scoped_ptr<BrowserThread> io_thread_; 278 scoped_ptr<BrowserThread> io_thread_;
284 scoped_ptr<BrowserThread> watchdog_thread_; 279 scoped_ptr<WatchDogThread> watchdog_thread_;
285 ThreadWatcherList* thread_watcher_list_; 280 ThreadWatcherList* thread_watcher_list_;
286 }; 281 };
287 282
288 // Define static constants. 283 // Define static constants.
289 const TimeDelta ThreadWatcherTest::kSleepTime = 284 const TimeDelta ThreadWatcherTest::kSleepTime =
290 TimeDelta::FromMilliseconds(50); 285 TimeDelta::FromMilliseconds(50);
291 const TimeDelta ThreadWatcherTest::kUnresponsiveTime = 286 const TimeDelta ThreadWatcherTest::kUnresponsiveTime =
292 TimeDelta::FromMilliseconds(500); 287 TimeDelta::FromMilliseconds(500);
293 const BrowserThread::ID ThreadWatcherTest::io_thread_id = BrowserThread::IO; 288 const BrowserThread::ID ThreadWatcherTest::io_thread_id = BrowserThread::IO;
294 const std::string ThreadWatcherTest::io_thread_name = "IO"; 289 const std::string ThreadWatcherTest::io_thread_name = "IO";
(...skipping 17 matching lines...) Expand all
312 // Check ThreadWatcher object of watched WEBKIT thread has correct data. 307 // Check ThreadWatcher object of watched WEBKIT thread has correct data.
313 EXPECT_EQ(webkit_thread_id, webkit_watcher_->thread_id()); 308 EXPECT_EQ(webkit_thread_id, webkit_watcher_->thread_id());
314 EXPECT_EQ(webkit_thread_name, webkit_watcher_->thread_name()); 309 EXPECT_EQ(webkit_thread_name, webkit_watcher_->thread_name());
315 EXPECT_EQ(kSleepTime, webkit_watcher_->sleep_time()); 310 EXPECT_EQ(kSleepTime, webkit_watcher_->sleep_time());
316 EXPECT_EQ(kUnresponsiveTime, webkit_watcher_->unresponsive_time()); 311 EXPECT_EQ(kUnresponsiveTime, webkit_watcher_->unresponsive_time());
317 EXPECT_FALSE(webkit_watcher_->active()); 312 EXPECT_FALSE(webkit_watcher_->active());
318 } 313 }
319 314
320 // Test ActivateThreadWatching and DeActivateThreadWatching of IO thread. This 315 // Test ActivateThreadWatching and DeActivateThreadWatching of IO thread. This
321 // method also checks that pong message was sent by the watched thread and pong 316 // method also checks that pong message was sent by the watched thread and pong
322 // message was received by the WATCHDOG thread. It also checks that 317 // message was received by the WatchDogThread. It also checks that
323 // OnCheckResponsiveness has verified the ping-pong mechanism and the watched 318 // OnCheckResponsiveness has verified the ping-pong mechanism and the watched
324 // thread is not hung. 319 // thread is not hung.
325 TEST_F(ThreadWatcherTest, ThreadResponding) { 320 TEST_F(ThreadWatcherTest, ThreadResponding) {
326 TimeTicks time_before_ping = TimeTicks::Now(); 321 TimeTicks time_before_ping = TimeTicks::Now();
327 // Activate watching IO thread. 322 // Activate watching IO thread.
328 BrowserThread::PostTask( 323 MessageLoop* message_loop = WatchDogThread::CurrentMessageLoop();
329 BrowserThread::WATCHDOG, 324 ASSERT_TRUE(message_loop != NULL);
325 message_loop->PostTask(
330 FROM_HERE, 326 FROM_HERE,
331 NewRunnableMethod(io_watcher_, &ThreadWatcher::ActivateThreadWatching)); 327 NewRunnableMethod(io_watcher_, &ThreadWatcher::ActivateThreadWatching));
332 328
333 // Activate would have started ping/pong messaging. Expect atleast one 329 // Activate would have started ping/pong messaging. Expect atleast one
334 // ping/pong messaging sequence to happen. 330 // ping/pong messaging sequence to happen.
335 io_watcher_->WaitForStateChange(kSleepTime + TimeDelta::FromMinutes(1), 331 io_watcher_->WaitForStateChange(kSleepTime + TimeDelta::FromMinutes(1),
336 RECEIVED_PONG); 332 RECEIVED_PONG);
337 io_watcher_->WaitForStateChange(kSleepTime + TimeDelta::FromMinutes(1), 333 io_watcher_->WaitForStateChange(kSleepTime + TimeDelta::FromMinutes(1),
338 SENT_PING); 334 SENT_PING);
339 EXPECT_GT(io_watcher_->ping_sent_, static_cast<uint64>(0)); 335 EXPECT_GT(io_watcher_->ping_sent_, static_cast<uint64>(0));
340 EXPECT_GT(io_watcher_->pong_received_, static_cast<uint64>(0)); 336 EXPECT_GT(io_watcher_->pong_received_, static_cast<uint64>(0));
341 EXPECT_TRUE(io_watcher_->active()); 337 EXPECT_TRUE(io_watcher_->active());
342 EXPECT_GE(io_watcher_->ping_time_, time_before_ping); 338 EXPECT_GE(io_watcher_->ping_time_, time_before_ping);
343 EXPECT_GE(io_watcher_->ping_sequence_number_, static_cast<uint64>(0)); 339 EXPECT_GE(io_watcher_->ping_sequence_number_, static_cast<uint64>(0));
344 340
345 // Verify watched thread is responding with ping/pong messaging. 341 // Verify watched thread is responding with ping/pong messaging.
346 io_watcher_->WaitForCheckResponse( 342 io_watcher_->WaitForCheckResponse(
347 kUnresponsiveTime + TimeDelta::FromMinutes(1), SUCCESSFUL); 343 kUnresponsiveTime + TimeDelta::FromMinutes(1), SUCCESSFUL);
348 EXPECT_GT(io_watcher_->success_response_, static_cast<uint64>(0)); 344 EXPECT_GT(io_watcher_->success_response_, static_cast<uint64>(0));
349 EXPECT_EQ(io_watcher_->failed_response_, static_cast<uint64>(0)); 345 EXPECT_EQ(io_watcher_->failed_response_, static_cast<uint64>(0));
350 346
351 // DeActivate thread watching for shutdown. 347 // DeActivate thread watching for shutdown.
352 BrowserThread::PostTask( 348 message_loop = WatchDogThread::CurrentMessageLoop();
353 BrowserThread::WATCHDOG, 349 ASSERT_TRUE(message_loop != NULL);
350 message_loop->PostTask(
354 FROM_HERE, 351 FROM_HERE,
355 NewRunnableMethod(io_watcher_, &ThreadWatcher::DeActivateThreadWatching)); 352 NewRunnableMethod(io_watcher_, &ThreadWatcher::DeActivateThreadWatching));
356 } 353 }
357 354
358 // This test posts a task on watched thread that takes very long time (this is 355 // This test posts a task on watched thread that takes very long time (this is
359 // to simulate hanging of watched thread). It then checks for 356 // to simulate hanging of watched thread). It then checks for
360 // OnCheckResponsiveness raising an alert (OnCheckResponsiveness returns false 357 // OnCheckResponsiveness raising an alert (OnCheckResponsiveness returns false
361 // if the watched thread is not responding). 358 // if the watched thread is not responding).
362 TEST_F(ThreadWatcherTest, ThreadNotResponding) { 359 TEST_F(ThreadWatcherTest, ThreadNotResponding) {
363 // Simulate hanging of watched thread by making the watched thread wait for a 360 // Simulate hanging of watched thread by making the watched thread wait for a
364 // very long time by posting a task on watched thread that keeps it busy. 361 // very long time by posting a task on watched thread that keeps it busy.
365 BrowserThread::PostTask( 362 BrowserThread::PostTask(
366 io_thread_id, 363 io_thread_id,
367 FROM_HERE, 364 FROM_HERE,
368 NewRunnableMethod( 365 NewRunnableMethod(
369 io_watcher_, 366 io_watcher_,
370 &CustomThreadWatcher::VeryLongMethod, 367 &CustomThreadWatcher::VeryLongMethod,
371 kUnresponsiveTime * 10)); 368 kUnresponsiveTime * 10));
372 369
373 // Activate thread watching. 370 // Activate thread watching.
374 BrowserThread::PostTask( 371 MessageLoop* message_loop = WatchDogThread::CurrentMessageLoop();
375 BrowserThread::WATCHDOG, 372 ASSERT_TRUE(message_loop != NULL);
373 message_loop->PostTask(
376 FROM_HERE, 374 FROM_HERE,
377 NewRunnableMethod(io_watcher_, &ThreadWatcher::ActivateThreadWatching)); 375 NewRunnableMethod(io_watcher_, &ThreadWatcher::ActivateThreadWatching));
378 376
379 // Verify watched thread is not responding for ping messages. 377 // Verify watched thread is not responding for ping messages.
380 io_watcher_->WaitForCheckResponse( 378 io_watcher_->WaitForCheckResponse(
381 kUnresponsiveTime + TimeDelta::FromMinutes(1), FAILED); 379 kUnresponsiveTime + TimeDelta::FromMinutes(1), FAILED);
382 EXPECT_EQ(io_watcher_->success_response_, static_cast<uint64>(0)); 380 EXPECT_EQ(io_watcher_->success_response_, static_cast<uint64>(0));
383 EXPECT_GT(io_watcher_->failed_response_, static_cast<uint64>(0)); 381 EXPECT_GT(io_watcher_->failed_response_, static_cast<uint64>(0));
384 382
385 // DeActivate thread watching for shutdown. 383 // DeActivate thread watching for shutdown.
386 BrowserThread::PostTask( 384 message_loop = WatchDogThread::CurrentMessageLoop();
387 BrowserThread::WATCHDOG, 385 ASSERT_TRUE(message_loop != NULL);
386 message_loop->PostTask(
388 FROM_HERE, 387 FROM_HERE,
389 NewRunnableMethod(io_watcher_, &ThreadWatcher::DeActivateThreadWatching)); 388 NewRunnableMethod(io_watcher_, &ThreadWatcher::DeActivateThreadWatching));
390 } 389 }
391 390
392 // Test watching of multiple threads with all threads not responding. 391 // Test watching of multiple threads with all threads not responding.
393 TEST_F(ThreadWatcherTest, MultipleThreadsResponding) { 392 TEST_F(ThreadWatcherTest, MultipleThreadsResponding) {
394 // Check for WEBKIT thread to perform ping/pong messaging. 393 // Check for WEBKIT thread to perform ping/pong messaging.
395 BrowserThread::PostTask( 394 MessageLoop* message_loop = WatchDogThread::CurrentMessageLoop();
396 BrowserThread::WATCHDOG, 395 ASSERT_TRUE(message_loop != NULL);
396 message_loop->PostTask(
397 FROM_HERE, 397 FROM_HERE,
398 NewRunnableMethod( 398 NewRunnableMethod(
399 webkit_watcher_, &ThreadWatcher::ActivateThreadWatching)); 399 webkit_watcher_, &ThreadWatcher::ActivateThreadWatching));
400
400 // Check for IO thread to perform ping/pong messaging. 401 // Check for IO thread to perform ping/pong messaging.
401 BrowserThread::PostTask( 402 message_loop->PostTask(
402 BrowserThread::WATCHDOG,
403 FROM_HERE, 403 FROM_HERE,
404 NewRunnableMethod(io_watcher_, &ThreadWatcher::ActivateThreadWatching)); 404 NewRunnableMethod(io_watcher_, &ThreadWatcher::ActivateThreadWatching));
405 405
406 // Verify WEBKIT thread is responding with ping/pong messaging. 406 // Verify WEBKIT thread is responding with ping/pong messaging.
407 webkit_watcher_->WaitForCheckResponse( 407 webkit_watcher_->WaitForCheckResponse(
408 kUnresponsiveTime + TimeDelta::FromMinutes(1), SUCCESSFUL); 408 kUnresponsiveTime + TimeDelta::FromMinutes(1), SUCCESSFUL);
409 EXPECT_GT(webkit_watcher_->ping_sent_, static_cast<uint64>(0)); 409 EXPECT_GT(webkit_watcher_->ping_sent_, static_cast<uint64>(0));
410 EXPECT_GT(webkit_watcher_->pong_received_, static_cast<uint64>(0)); 410 EXPECT_GT(webkit_watcher_->pong_received_, static_cast<uint64>(0));
411 EXPECT_GE(webkit_watcher_->ping_sequence_number_, static_cast<uint64>(0)); 411 EXPECT_GE(webkit_watcher_->ping_sequence_number_, static_cast<uint64>(0));
412 EXPECT_GT(webkit_watcher_->success_response_, static_cast<uint64>(0)); 412 EXPECT_GT(webkit_watcher_->success_response_, static_cast<uint64>(0));
413 EXPECT_EQ(webkit_watcher_->failed_response_, static_cast<uint64>(0)); 413 EXPECT_EQ(webkit_watcher_->failed_response_, static_cast<uint64>(0));
414 414
415 // Verify IO thread is responding with ping/pong messaging. 415 // Verify IO thread is responding with ping/pong messaging.
416 io_watcher_->WaitForCheckResponse( 416 io_watcher_->WaitForCheckResponse(
417 kUnresponsiveTime + TimeDelta::FromMinutes(1), SUCCESSFUL); 417 kUnresponsiveTime + TimeDelta::FromMinutes(1), SUCCESSFUL);
418 EXPECT_GT(io_watcher_->ping_sent_, static_cast<uint64>(0)); 418 EXPECT_GT(io_watcher_->ping_sent_, static_cast<uint64>(0));
419 EXPECT_GT(io_watcher_->pong_received_, static_cast<uint64>(0)); 419 EXPECT_GT(io_watcher_->pong_received_, static_cast<uint64>(0));
420 EXPECT_GE(io_watcher_->ping_sequence_number_, static_cast<uint64>(0)); 420 EXPECT_GE(io_watcher_->ping_sequence_number_, static_cast<uint64>(0));
421 EXPECT_GT(io_watcher_->success_response_, static_cast<uint64>(0)); 421 EXPECT_GT(io_watcher_->success_response_, static_cast<uint64>(0));
422 EXPECT_EQ(io_watcher_->failed_response_, static_cast<uint64>(0)); 422 EXPECT_EQ(io_watcher_->failed_response_, static_cast<uint64>(0));
423 423
424 // DeActivate thread watching for shutdown. 424 // DeActivate thread watching for shutdown.
425 BrowserThread::PostTask( 425 message_loop = WatchDogThread::CurrentMessageLoop();
426 BrowserThread::WATCHDOG, 426 ASSERT_TRUE(message_loop != NULL);
427 message_loop->PostTask(
427 FROM_HERE, 428 FROM_HERE,
428 NewRunnableMethod(io_watcher_, &ThreadWatcher::DeActivateThreadWatching)); 429 NewRunnableMethod(
429 BrowserThread::PostTask( 430 io_watcher_, &ThreadWatcher::DeActivateThreadWatching));
430 BrowserThread::WATCHDOG, 431
432 message_loop->PostTask(
431 FROM_HERE, 433 FROM_HERE,
432 NewRunnableMethod( 434 NewRunnableMethod(
433 webkit_watcher_, &ThreadWatcher::DeActivateThreadWatching)); 435 webkit_watcher_, &ThreadWatcher::DeActivateThreadWatching));
434 } 436 }
435 437
436 // Test watching of multiple threads with one of the threads not responding. 438 // Test watching of multiple threads with one of the threads not responding.
437 TEST_F(ThreadWatcherTest, MultipleThreadsNotResponding) { 439 TEST_F(ThreadWatcherTest, MultipleThreadsNotResponding) {
438 // Simulate hanging of watched thread by making the watched thread wait for a 440 // Simulate hanging of watched thread by making the watched thread wait for a
439 // very long time by posting a task on watched thread that keeps it busy. 441 // very long time by posting a task on watched thread that keeps it busy.
440 BrowserThread::PostTask( 442 BrowserThread::PostTask(
441 io_thread_id, 443 io_thread_id,
442 FROM_HERE, 444 FROM_HERE,
443 NewRunnableMethod( 445 NewRunnableMethod(
444 io_watcher_, 446 io_watcher_,
445 &CustomThreadWatcher::VeryLongMethod, 447 &CustomThreadWatcher::VeryLongMethod,
446 kUnresponsiveTime * 10)); 448 kUnresponsiveTime * 10));
447 449
448 // Activate watching of WEBKIT thread. 450 // Activate watching of WEBKIT thread.
449 BrowserThread::PostTask( 451 MessageLoop* message_loop = WatchDogThread::CurrentMessageLoop();
450 BrowserThread::WATCHDOG, 452 ASSERT_TRUE(message_loop != NULL);
453 message_loop->PostTask(
451 FROM_HERE, 454 FROM_HERE,
452 NewRunnableMethod( 455 NewRunnableMethod(
453 webkit_watcher_, &ThreadWatcher::ActivateThreadWatching)); 456 webkit_watcher_, &ThreadWatcher::ActivateThreadWatching));
454 457
455 // Activate watching of IO thread. 458 // Activate watching of IO thread.
456 BrowserThread::PostTask( 459 message_loop->PostTask(
457 BrowserThread::WATCHDOG,
458 FROM_HERE, 460 FROM_HERE,
459 NewRunnableMethod(io_watcher_, &ThreadWatcher::ActivateThreadWatching)); 461 NewRunnableMethod(io_watcher_, &ThreadWatcher::ActivateThreadWatching));
460 462
461 // Verify WEBKIT thread is responding with ping/pong messaging. 463 // Verify WEBKIT thread is responding with ping/pong messaging.
462 webkit_watcher_->WaitForCheckResponse( 464 webkit_watcher_->WaitForCheckResponse(
463 kUnresponsiveTime + TimeDelta::FromMinutes(1), SUCCESSFUL); 465 kUnresponsiveTime + TimeDelta::FromMinutes(1), SUCCESSFUL);
464 EXPECT_GT(webkit_watcher_->success_response_, static_cast<uint64>(0)); 466 EXPECT_GT(webkit_watcher_->success_response_, static_cast<uint64>(0));
465 EXPECT_EQ(webkit_watcher_->failed_response_, static_cast<uint64>(0)); 467 EXPECT_EQ(webkit_watcher_->failed_response_, static_cast<uint64>(0));
466 468
467 // Verify IO thread is not responding for ping messages. 469 // Verify IO thread is not responding for ping messages.
468 io_watcher_->WaitForCheckResponse( 470 io_watcher_->WaitForCheckResponse(
469 kUnresponsiveTime + TimeDelta::FromMinutes(1), FAILED); 471 kUnresponsiveTime + TimeDelta::FromMinutes(1), FAILED);
470 EXPECT_EQ(io_watcher_->success_response_, static_cast<uint64>(0)); 472 EXPECT_EQ(io_watcher_->success_response_, static_cast<uint64>(0));
471 EXPECT_GT(io_watcher_->failed_response_, static_cast<uint64>(0)); 473 EXPECT_GT(io_watcher_->failed_response_, static_cast<uint64>(0));
472 474
473 // DeActivate thread watching for shutdown. 475 // DeActivate thread watching for shutdown.
474 BrowserThread::PostTask( 476 message_loop = WatchDogThread::CurrentMessageLoop();
475 BrowserThread::WATCHDOG, 477 ASSERT_TRUE(message_loop != NULL);
478 message_loop->PostTask(
476 FROM_HERE, 479 FROM_HERE,
477 NewRunnableMethod(io_watcher_, &ThreadWatcher::DeActivateThreadWatching)); 480 NewRunnableMethod(io_watcher_, &ThreadWatcher::DeActivateThreadWatching));
478 BrowserThread::PostTask( 481 message_loop->PostTask(
479 BrowserThread::WATCHDOG,
480 FROM_HERE, 482 FROM_HERE,
481 NewRunnableMethod( 483 NewRunnableMethod(
482 webkit_watcher_, &ThreadWatcher::DeActivateThreadWatching)); 484 webkit_watcher_, &ThreadWatcher::DeActivateThreadWatching));
483 } 485 }
484
485 #endif // 0
OLDNEW
« no previous file with comments | « chrome/browser/metrics/thread_watcher.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698