OLD | NEW |
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::FromSeconds(1), |
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 a second. |
83 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromSeconds(1), | 83 // In practice, on our trybots, it sometimes takes a little longer! |
| 84 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMilliseconds(1500), |
84 watchdog.alarm_counter() > 1); | 85 watchdog.alarm_counter() > 1); |
85 | 86 |
86 EXPECT_EQ(2, watchdog.alarm_counter()); | 87 EXPECT_EQ(2, watchdog.alarm_counter()); |
87 } | 88 } |
88 | 89 |
89 // Make sure a disable alarm does nothing, even if we arm it. | 90 // Make sure a disable alarm does nothing, even if we arm it. |
90 TEST(WatchdogTest, ConstructorDisabledTest) { | 91 TEST(WatchdogTest, ConstructorDisabledTest) { |
91 WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Disabled", false); | 92 WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Disabled", false); |
92 watchdog.Arm(); | 93 watchdog.Arm(); |
93 // Alarm should not fire, as it was disabled. | 94 // Alarm should not fire, as it was disabled. |
(...skipping 16 matching lines...) Expand all Loading... |
110 watchdog.ArmSomeTimeDeltaAgo(TimeDelta::FromSeconds(2)); | 111 watchdog.ArmSomeTimeDeltaAgo(TimeDelta::FromSeconds(2)); |
111 // It should almost instantly go off, but certainly in less than a second. | 112 // It should almost instantly go off, but certainly in less than a second. |
112 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromSeconds(1), | 113 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromSeconds(1), |
113 watchdog.alarm_counter() > 0); | 114 watchdog.alarm_counter() > 0); |
114 | 115 |
115 EXPECT_EQ(1, watchdog.alarm_counter()); | 116 EXPECT_EQ(1, watchdog.alarm_counter()); |
116 } | 117 } |
117 | 118 |
118 } // namespace | 119 } // namespace |
119 | 120 |
OLD | NEW |