Add 10 minute random fuzz to automatic update check event schedule.
Schedules the initial check at 7 minutes and periodic checks at 45 minutes
with +/- 5 minute fuzz.
BUG=5983
TEST=unit tests, gmerged on device, inspected logs, observed checks
Change-Id: Ifd38574c4265fec78f6e330f965c2b1054b2dddb
Review URL: http://codereview.chromium.org/3173041
diff --git a/utils_unittest.cc b/utils_unittest.cc
index 70eb6c7..3514f8a 100644
--- a/utils_unittest.cc
+++ b/utils_unittest.cc
@@ -5,9 +5,11 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
+
#include <string>
#include <vector>
-#include <gtest/gtest.h>
+
+#include "gtest/gtest.h"
#include "update_engine/utils.h"
using std::string;
@@ -157,7 +159,7 @@
EXPECT_EQ("3", utils::PartitionNumber("/dev/mmc0p3"));
}
-TEST(UtilsTest, ComparePriorities) {
+TEST(UtilsTest, ComparePrioritiesTest) {
EXPECT_LT(utils::ComparePriorities(utils::kProcessPriorityLow,
utils::kProcessPriorityNormal), 0);
EXPECT_GT(utils::ComparePriorities(utils::kProcessPriorityNormal,
@@ -168,4 +170,17 @@
utils::kProcessPriorityNormal), 0);
}
+TEST(UtilsTest, FuzzIntTest) {
+ static const unsigned int kRanges[] = { 0, 1, 2, 20 };
+ for (size_t r = 0; r < arraysize(kRanges); ++r) {
+ unsigned int range = kRanges[r];
+ const int kValue = 50;
+ for (int tries = 0; tries < 100; ++tries) {
+ int value = utils::FuzzInt(kValue, range);
+ EXPECT_GE(value, kValue - range / 2);
+ EXPECT_LE(value, kValue + range - range / 2);
+ }
+ }
+}
+
} // namespace chromeos_update_engine