shill: diags: Don't throttle the first connectivity event.
BUG=chromium-os:37295
TEST=unit tests; tested on device
Change-Id: If861627577f27baf41ab60ee51ca9aa6fd982dd4
Reviewed-on: https://gerrit.chromium.org/gerrit/39768
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Ready: Darin Petkov <petkov@chromium.org>
diff --git a/diagnostics_reporter.cc b/diagnostics_reporter.cc
index f464c79..4935f98 100644
--- a/diagnostics_reporter.cc
+++ b/diagnostics_reporter.cc
@@ -40,7 +40,8 @@
struct timeval now = (const struct timeval){ 0 };
time_->GetTimeMonotonic(&now);
- if (last_log_stash_ + kLogStashThrottleSeconds >
+ if (last_log_stash_ &&
+ last_log_stash_ + kLogStashThrottleSeconds >
static_cast<uint64>(now.tv_sec)) {
LOG(INFO) << "Diagnostics throttled.";
return;
diff --git a/diagnostics_reporter_unittest.cc b/diagnostics_reporter_unittest.cc
index 028b847..5f538fc 100644
--- a/diagnostics_reporter_unittest.cc
+++ b/diagnostics_reporter_unittest.cc
@@ -85,9 +85,10 @@
} // namespace
TEST_F(DiagnosticsReporterTest, OnConnectivityEvent) {
- const uint64 kLastStash = 50;
- SetLastLogStash(kLastStash);
- const uint64 kNow0 = kLastStash + GetLogStashThrottleSeconds() + 1;
+ const uint64 kInitStash = 0;
+ SetLastLogStash(kInitStash);
+ // Test that the initial call is not throttled.
+ const uint64 kNow0 = kInitStash + 1;
const struct timeval now0 = {
.tv_sec = static_cast<long int>(kNow0),
.tv_usec = 0