summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-28 22:17:29 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-28 22:17:29 +0000
commitb045a7405237ec931bf137f2c555960fa64a9523 (patch)
tree7fefdf182c96e1f6304cc74c61589a7b008123d7 /base
parent0e4da3d4aa6d804fb55d798a439603d020847caf (diff)
downloadchromium_src-b045a7405237ec931bf137f2c555960fa64a9523.zip
chromium_src-b045a7405237ec931bf137f2c555960fa64a9523.tar.gz
chromium_src-b045a7405237ec931bf137f2c555960fa64a9523.tar.bz2
base_unittests: cut a sleep down to 1 second by being more careful about time.
TEST=WatchdogTest.DisarmTest doesn't go flaky Review URL: http://codereview.chromium.org/3545001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60853 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/watchdog_unittest.cc29
1 files changed, 23 insertions, 6 deletions
diff --git a/base/watchdog_unittest.cc b/base/watchdog_unittest.cc
index f16c564..19dfe28 100644
--- a/base/watchdog_unittest.cc
+++ b/base/watchdog_unittest.cc
@@ -1,16 +1,19 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Tests for Watchdog class.
+#include "base/watchdog.h"
+
+#include "base/logging.h"
#include "base/platform_thread.h"
#include "base/spin_wait.h"
#include "base/time.h"
-#include "base/watchdog.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::TimeDelta;
+using base::TimeTicks;
namespace {
@@ -104,12 +107,26 @@ TEST_F(WatchdogTest, ConstructorDisabledTest) {
// Make sure Disarming will prevent firing, even after Arming.
TEST_F(WatchdogTest, DisarmTest) {
- WatchdogCounter watchdog(TimeDelta::FromSeconds(5), "Enabled3", true);
+ WatchdogCounter watchdog(TimeDelta::FromSeconds(1), "Enabled3", true);
+
+ TimeTicks start = TimeTicks::Now();
watchdog.Arm();
- PlatformThread::Sleep(100); // Don't sleep too long
+ PlatformThread::Sleep(100); // Sleep a bit, but not past the alarm point.
watchdog.Disarm();
- // Alarm should not fire.
- PlatformThread::Sleep(5500);
+ TimeTicks end = TimeTicks::Now();
+
+ if (end - start > TimeDelta::FromMilliseconds(500)) {
+ LOG(WARNING) << "100ms sleep took over 500ms, making the results of this "
+ << "timing-sensitive test suspicious. Aborting now.";
+ return;
+ }
+
+ // Alarm should not have fired before it was disarmed.
+ EXPECT_EQ(0, watchdog.alarm_counter());
+
+ // Sleep past the point where it would have fired if it wasn't disarmed,
+ // and verify that it didn't fire.
+ PlatformThread::Sleep(1000);
EXPECT_EQ(0, watchdog.alarm_counter());
// ...but even after disarming, we can still use the alarm...