summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-03 19:28:59 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-03 19:28:59 +0000
commit9999b28465395531a59c8c512ea80a41c7e99bbc (patch)
tree2a891ebd4519dfe3cc67f050be1033fb9eb0820a /base
parentfeeb805c66b62bcc68626c9a0e47febd41ed2d8d (diff)
downloadchromium_src-9999b28465395531a59c8c512ea80a41c7e99bbc.zip
chromium_src-9999b28465395531a59c8c512ea80a41c7e99bbc.tar.gz
chromium_src-9999b28465395531a59c8c512ea80a41c7e99bbc.tar.bz2
Update idle timer test to use longer intervals.
This should increase reliability issues seen on the bbots. Review URL: http://codereview.chromium.org/9261 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4471 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/idletimer_unittest.cc73
1 files changed, 40 insertions, 33 deletions
diff --git a/base/idletimer_unittest.cc b/base/idletimer_unittest.cc
index ea43262..2acfce3 100644
--- a/base/idletimer_unittest.cc
+++ b/base/idletimer_unittest.cc
@@ -10,6 +10,13 @@ using base::Time;
using base::TimeDelta;
using base::IdleTimer;
+
+// If the timers fire too quickly, it can be tricky to make timer tests
+// reliable on all buildbots. This constant sets a minimum timer delta where
+// we expect that we should be able to reliably count timers without problems
+// due to slight clock/scheduling variances.
+const int kSafeTestIntervalMs = 500;
+
namespace {
// We Mock the GetLastInputInfo function to return
@@ -27,7 +34,7 @@ bool MockIdleTimeSource(int32 *milliseconds_interval_since_last_event) {
class TestIdleTask : public IdleTimer {
public:
TestIdleTask(bool repeat)
- : IdleTimer(TimeDelta::FromMilliseconds(100), repeat),
+ : IdleTimer(TimeDelta::FromMilliseconds(kSafeTestIntervalMs), repeat),
idle_counter_(0) {
set_idle_time_source(MockIdleTimeSource);
}
@@ -72,7 +79,7 @@ class IdleTimerTest : public testing::Test {
// then will not fire again unless it goes non-idle first.
TEST_F(IdleTimerTest, NoRepeatIdle) {
- // Create an IdleTimer, which should fire once after 100ms.
+ // Create an IdleTimer, which should fire once after 500ms.
// Create a Quit timer which will fire after 1s.
// Verify that we fired exactly once.
@@ -81,7 +88,8 @@ TEST_F(IdleTimerTest, NoRepeatIdle) {
TestFinishedTask finish_task;
base::OneShotTimer<TestFinishedTask> timer;
- timer.Start(TimeDelta::FromSeconds(1), &finish_task, &TestFinishedTask::Run);
+ timer.Start(TimeDelta::FromMilliseconds(2 * kSafeTestIntervalMs),
+ &finish_task, &TestFinishedTask::Run);
test_task.Start();
MessageLoop::current()->Run();
@@ -90,9 +98,9 @@ TEST_F(IdleTimerTest, NoRepeatIdle) {
}
TEST_F(IdleTimerTest, NoRepeatFlipIdleOnce) {
- // Create an IdleTimer, which should fire once after 100ms.
- // Create a Quit timer which will fire after 1s.
- // Create a timer to reset once, idle after 500ms.
+ // Create an IdleTimer, which should fire once after 500ms.
+ // Create a Quit timer which will fire after 5s.
+ // Create a timer to reset once, idle after 2s.
// Verify that we fired exactly twice.
mock_timer_started = Time::Now();
@@ -102,11 +110,11 @@ TEST_F(IdleTimerTest, NoRepeatFlipIdleOnce) {
ResetIdleTask reset_task;
base::OneShotTimer<TestFinishedTask> t1;
- t1.Start(TimeDelta::FromMilliseconds(1000), &finish_task,
+ t1.Start(TimeDelta::FromMilliseconds(10 * kSafeTestIntervalMs), &finish_task,
&TestFinishedTask::Run);
base::OneShotTimer<ResetIdleTask> t2;
- t2.Start(TimeDelta::FromMilliseconds(500), &reset_task,
+ t2.Start(TimeDelta::FromMilliseconds(4 * kSafeTestIntervalMs), &reset_task,
&ResetIdleTask::Run);
test_task.Start();
@@ -117,8 +125,8 @@ TEST_F(IdleTimerTest, NoRepeatFlipIdleOnce) {
// TODO(darin): http://crbug.com/3704
TEST_F(IdleTimerTest, DISABLED_NoRepeatNotIdle) {
- // Create an IdleTimer, which should fire once after 100ms.
- // Create a Quit timer which will fire after 1s.
+ // Create an IdleTimer, which should fire once after 500ms.
+ // Create a Quit timer which will fire after 5s.
// Create a timer to reset idle every 50ms.
// Verify that we never fired.
@@ -129,7 +137,7 @@ TEST_F(IdleTimerTest, DISABLED_NoRepeatNotIdle) {
ResetIdleTask reset_task;
base::OneShotTimer<TestFinishedTask> t;
- t.Start(TimeDelta::FromMilliseconds(1000), &finish_task,
+ t.Start(TimeDelta::FromMilliseconds(10 * kSafeTestIntervalMs), &finish_task,
&TestFinishedTask::Run);
base::RepeatingTimer<ResetIdleTask> reset_timer;
@@ -152,34 +160,33 @@ TEST_F(IdleTimerTest, DISABLED_NoRepeatNotIdle) {
// firing over and over.
TEST_F(IdleTimerTest, Repeat) {
- // Create an IdleTimer, which should fire repeatedly after 100ms.
- // Create a Quit timer which will fire after 1.05s.
- // Verify that we fired 10 times.
+ // Create an IdleTimer, which should fire repeatedly after 500ms.
+ // Create a Quit timer which will fire after 1.5s.
+ // Verify that we fired 2-3 times.
mock_timer_started = Time::Now();
TestIdleTask test_task(true);
TestFinishedTask finish_task;
base::OneShotTimer<TestFinishedTask> t;
- t.Start(TimeDelta::FromMilliseconds(1050), &finish_task,
+ t.Start(TimeDelta::FromMilliseconds(kSafeTestIntervalMs * 3), &finish_task,
&TestFinishedTask::Run);
test_task.Start();
MessageLoop::current()->Run();
- // In a perfect world, the idle_counter should be 10. However,
- // since timers aren't guaranteed to fire perfectly, this can
- // be less. Just expect more than 5 and no more than 10.
- EXPECT_GT(test_task.get_idle_counter(), 5);
- EXPECT_LE(test_task.get_idle_counter(), 10);
+ // In a perfect world, the idle_counter should be 2. However,
+ // due to timer 'slop', accept 2 or 3.
+ EXPECT_GE(test_task.get_idle_counter(), 2);
+ EXPECT_LE(test_task.get_idle_counter(), 3);
}
// TODO(darin): http://crbug.com/3780
-TEST_F(IdleTimerTest, DISABLED_RepeatIdleReset) {
- // Create an IdleTimer, which should fire repeatedly after 100ms.
- // Create a Quit timer which will fire after 1s.
- // Create a reset timer, which fires after 550ms
- // Verify that we fired 9 times.
+TEST_F(IdleTimerTest, RepeatIdleReset) {
+ // Create an IdleTimer, which should fire repeatedly after 500ms.
+ // Create a Quit timer which will fire after 5s.
+ // Create a reset timer, which fires after 2500ms
+ // Verify that we fired 8-10 times.
mock_timer_started = Time::Now();
TestIdleTask test_task(true);
@@ -187,11 +194,11 @@ TEST_F(IdleTimerTest, DISABLED_RepeatIdleReset) {
TestFinishedTask finish_task;
base::OneShotTimer<TestFinishedTask> t1;
- t1.Start(TimeDelta::FromMilliseconds(1000), &finish_task,
+ t1.Start(TimeDelta::FromMilliseconds(10 * kSafeTestIntervalMs), &finish_task,
&TestFinishedTask::Run);
base::OneShotTimer<ResetIdleTask> t2;
- t2.Start(TimeDelta::FromMilliseconds(550), &reset_task,
+ t2.Start(TimeDelta::FromMilliseconds(5 * kSafeTestIntervalMs), &reset_task,
&ResetIdleTask::Run);
test_task.Start();
@@ -199,15 +206,15 @@ TEST_F(IdleTimerTest, DISABLED_RepeatIdleReset) {
// In a perfect world, the idle_counter should be 9. However,
// since timers aren't guaranteed to fire perfectly, this can
- // be less. Just expect more than 5 and no more than 9.
- EXPECT_GT(test_task.get_idle_counter(), 5);
- EXPECT_LE(test_task.get_idle_counter(), 9);
+ // be less. Accept 8-10.
+ EXPECT_GE(test_task.get_idle_counter(), 8);
+ EXPECT_LE(test_task.get_idle_counter(), 10);
}
// TODO(darin): http://crbug.com/3704
TEST_F(IdleTimerTest, DISABLED_RepeatNotIdle) {
- // Create an IdleTimer, which should fire repeatedly after 100ms.
- // Create a Quit timer which will fire after 1s.
+ // Create an IdleTimer, which should fire repeatedly after 500ms.
+ // Create a Quit timer which will fire after 4s.
// Create a timer to reset idle every 50ms.
// Verify that we never fired.
@@ -218,7 +225,7 @@ TEST_F(IdleTimerTest, DISABLED_RepeatNotIdle) {
ResetIdleTask reset_task;
base::OneShotTimer<TestFinishedTask> t;
- t.Start(TimeDelta::FromMilliseconds(1000), &finish_task,
+ t.Start(TimeDelta::FromMilliseconds(8 * kSafeTestIntervalMs), &finish_task,
&TestFinishedTask::Run);
base::RepeatingTimer<ResetIdleTask> reset_timer;