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

Side by Side Diff: base/watchdog_unittest.cc

Issue 16495: Significantly increase timeouts to reduce flakiness... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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 | « no previous file | 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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // Tests for Watchdog class. 5 // Tests for Watchdog class.
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/platform_thread.h" 8 #include "base/platform_thread.h"
9 #include "base/spin_wait.h" 9 #include "base/spin_wait.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 watchdog2.Arm(); 66 watchdog2.Arm();
67 watchdog2.Disarm(); 67 watchdog2.Disarm();
68 watchdog2.Arm(); 68 watchdog2.Arm();
69 watchdog2.Disarm(); 69 watchdog2.Disarm();
70 } 70 }
71 71
72 // Make sure a basic alarm fires when the time has expired. 72 // Make sure a basic alarm fires when the time has expired.
73 TEST(WatchdogTest, AlarmTest) { 73 TEST(WatchdogTest, AlarmTest) {
74 WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Enabled", true); 74 WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Enabled", true);
75 watchdog.Arm(); 75 watchdog.Arm();
76 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromSeconds(1), 76 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMinutes(5),
77 watchdog.alarm_counter() > 0); 77 watchdog.alarm_counter() > 0);
78 EXPECT_EQ(1, watchdog.alarm_counter()); 78 EXPECT_EQ(1, watchdog.alarm_counter());
79 79
80 // Set a time greater than the timeout into the past. 80 // Set a time greater than the timeout into the past.
81 watchdog.ArmSomeTimeDeltaAgo(TimeDelta::FromSeconds(2)); 81 watchdog.ArmSomeTimeDeltaAgo(TimeDelta::FromSeconds(2));
82 // It should instantly go off, but certainly in less than a second. 82 // It should instantly go off, but certainly in less than 5 minutes.
83 // In practice, on our trybots, it sometimes takes a little longer! 83 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMinutes(5),
84 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMilliseconds(1500),
85 watchdog.alarm_counter() > 1); 84 watchdog.alarm_counter() > 1);
86 85
87 EXPECT_EQ(2, watchdog.alarm_counter()); 86 EXPECT_EQ(2, watchdog.alarm_counter());
88 } 87 }
89 88
90 // Make sure a disable alarm does nothing, even if we arm it. 89 // Make sure a disable alarm does nothing, even if we arm it.
91 TEST(WatchdogTest, ConstructorDisabledTest) { 90 TEST(WatchdogTest, ConstructorDisabledTest) {
92 WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Disabled", false); 91 WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Disabled", false);
93 watchdog.Arm(); 92 watchdog.Arm();
94 // Alarm should not fire, as it was disabled. 93 // Alarm should not fire, as it was disabled.
95 PlatformThread::Sleep(500); 94 PlatformThread::Sleep(500);
96 EXPECT_EQ(0, watchdog.alarm_counter()); 95 EXPECT_EQ(0, watchdog.alarm_counter());
97 } 96 }
98 97
99 // Make sure Disarming will prevent firing, even after Arming. 98 // Make sure Disarming will prevent firing, even after Arming.
100 TEST(WatchdogTest, DisarmTest) { 99 TEST(WatchdogTest, DisarmTest) {
101 WatchdogCounter watchdog(TimeDelta::FromSeconds(1), "Enabled", true); 100 WatchdogCounter watchdog(TimeDelta::FromSeconds(5), "Enabled", true);
102 watchdog.Arm(); 101 watchdog.Arm();
103 PlatformThread::Sleep(100); // Don't sleep too long 102 PlatformThread::Sleep(100); // Don't sleep too long
104 watchdog.Disarm(); 103 watchdog.Disarm();
105 // Alarm should not fire. 104 // Alarm should not fire.
106 PlatformThread::Sleep(1500); 105 PlatformThread::Sleep(5500);
107 EXPECT_EQ(0, watchdog.alarm_counter()); 106 EXPECT_EQ(0, watchdog.alarm_counter());
108 107
109 // ...but even after disarming, we can still use the alarm... 108 // ...but even after disarming, we can still use the alarm...
110 // Set a time greater than the timeout into the past. 109 // Set a time greater than the timeout into the past.
111 watchdog.ArmSomeTimeDeltaAgo(TimeDelta::FromSeconds(2)); 110 watchdog.ArmSomeTimeDeltaAgo(TimeDelta::FromSeconds(2));
112 // It should almost instantly go off, but certainly in less than a second. 111 // It should almost instantly go off, but certainly in less than 5 minutes.
113 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromSeconds(1), 112 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMinutes(5),
114 watchdog.alarm_counter() > 0); 113 watchdog.alarm_counter() > 0);
115 114
116 EXPECT_EQ(1, watchdog.alarm_counter()); 115 EXPECT_EQ(1, watchdog.alarm_counter());
117 } 116 }
118 117
119 } // namespace 118 } // namespace
120 119
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698