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

Side by Side Diff: base/watchdog_unittest.cc

Issue 42266: Break up unit test to avoid internal timing interactions between parts.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | « base/watchdog.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 (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/platform_thread.h" 7 #include "base/platform_thread.h"
8 #include "base/spin_wait.h" 8 #include "base/spin_wait.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/watchdog.h" 10 #include "base/watchdog.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 watchdog2.Disarm(); 68 watchdog2.Disarm();
69 } 69 }
70 70
71 // Make sure a basic alarm fires when the time has expired. 71 // Make sure a basic alarm fires when the time has expired.
72 TEST(WatchdogTest, AlarmTest) { 72 TEST(WatchdogTest, AlarmTest) {
73 WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Enabled", true); 73 WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Enabled", true);
74 watchdog.Arm(); 74 watchdog.Arm();
75 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMinutes(5), 75 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMinutes(5),
76 watchdog.alarm_counter() > 0); 76 watchdog.alarm_counter() > 0);
77 EXPECT_EQ(1, watchdog.alarm_counter()); 77 EXPECT_EQ(1, watchdog.alarm_counter());
78 }
78 79
79 // Set a time greater than the timeout into the past. 80 // Make sure a basic alarm fires when the time has expired.
wtc 2009/06/04 23:14:24 This comment should show how AlarmPriorTimeTest di
81 TEST(WatchdogTest, AlarmPriorTimeTest) {
82 WatchdogCounter watchdog(TimeDelta::TimeDelta(), "Enabled2", true);
wtc 2009/06/04 23:14:24 Why is the first argument TimeDelta::TimeDelta() i
83 // Set a time in the past.
80 watchdog.ArmSomeTimeDeltaAgo(TimeDelta::FromSeconds(2)); 84 watchdog.ArmSomeTimeDeltaAgo(TimeDelta::FromSeconds(2));
81 // It should instantly go off, but certainly in less than 5 minutes. 85 // It should instantly go off, but certainly in less than 5 minutes.
82 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMinutes(5), 86 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMinutes(5),
83 watchdog.alarm_counter() > 1); 87 watchdog.alarm_counter() > 0);
84 88
85 EXPECT_EQ(2, watchdog.alarm_counter()); 89 EXPECT_EQ(1, watchdog.alarm_counter());
86 } 90 }
87 91
88 // Make sure a disable alarm does nothing, even if we arm it. 92 // Make sure a disable alarm does nothing, even if we arm it.
89 TEST(WatchdogTest, ConstructorDisabledTest) { 93 TEST(WatchdogTest, ConstructorDisabledTest) {
90 WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Disabled", false); 94 WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Disabled", false);
91 watchdog.Arm(); 95 watchdog.Arm();
92 // Alarm should not fire, as it was disabled. 96 // Alarm should not fire, as it was disabled.
93 PlatformThread::Sleep(500); 97 PlatformThread::Sleep(500);
94 EXPECT_EQ(0, watchdog.alarm_counter()); 98 EXPECT_EQ(0, watchdog.alarm_counter());
95 } 99 }
96 100
97 // Make sure Disarming will prevent firing, even after Arming. 101 // Make sure Disarming will prevent firing, even after Arming.
98 TEST(WatchdogTest, DisarmTest) { 102 TEST(WatchdogTest, DisarmTest) {
99 WatchdogCounter watchdog(TimeDelta::FromSeconds(5), "Enabled", true); 103 WatchdogCounter watchdog(TimeDelta::FromSeconds(5), "Enabled3", true);
100 watchdog.Arm(); 104 watchdog.Arm();
101 PlatformThread::Sleep(100); // Don't sleep too long 105 PlatformThread::Sleep(100); // Don't sleep too long
102 watchdog.Disarm(); 106 watchdog.Disarm();
103 // Alarm should not fire. 107 // Alarm should not fire.
104 PlatformThread::Sleep(5500); 108 PlatformThread::Sleep(5500);
105 EXPECT_EQ(0, watchdog.alarm_counter()); 109 EXPECT_EQ(0, watchdog.alarm_counter());
106 110
107 // ...but even after disarming, we can still use the alarm... 111 // ...but even after disarming, we can still use the alarm...
108 // Set a time greater than the timeout into the past. 112 // Set a time greater than the timeout into the past.
109 watchdog.ArmSomeTimeDeltaAgo(TimeDelta::FromSeconds(2)); 113 watchdog.ArmSomeTimeDeltaAgo(TimeDelta::FromSeconds(2));
110 // It should almost instantly go off, but certainly in less than 5 minutes. 114 // It should almost instantly go off, but certainly in less than 5 minutes.
111 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMinutes(5), 115 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMinutes(5),
112 watchdog.alarm_counter() > 0); 116 watchdog.alarm_counter() > 0);
113 117
114 EXPECT_EQ(1, watchdog.alarm_counter()); 118 EXPECT_EQ(1, watchdog.alarm_counter());
115 } 119 }
116 120
117 } // namespace 121 } // namespace
OLDNEW
« no previous file with comments | « base/watchdog.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698