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

Side by Side Diff: update_check_scheduler_unittest.cc

Issue 3275006: AU: Implement server-dictated poll interval. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: rebase to head Created 10 years, 3 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 | « update_check_scheduler.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) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 #include <gtest/gtest.h> 5 #include <gtest/gtest.h>
6 6
7 #include "update_engine/update_attempter_mock.h" 7 #include "update_engine/update_attempter_mock.h"
8 #include "update_engine/update_check_scheduler.h" 8 #include "update_engine/update_check_scheduler.h"
9 9
10 using std::string; 10 using std::string;
(...skipping 30 matching lines...) Expand all
41 UpdateCheckSchedulerTest() : scheduler_(&attempter_) {} 41 UpdateCheckSchedulerTest() : scheduler_(&attempter_) {}
42 42
43 protected: 43 protected:
44 virtual void SetUp() { 44 virtual void SetUp() {
45 test_ = this; 45 test_ = this;
46 loop_ = NULL; 46 loop_ = NULL;
47 EXPECT_EQ(&attempter_, scheduler_.update_attempter_); 47 EXPECT_EQ(&attempter_, scheduler_.update_attempter_);
48 EXPECT_FALSE(scheduler_.enabled_); 48 EXPECT_FALSE(scheduler_.enabled_);
49 EXPECT_FALSE(scheduler_.scheduled_); 49 EXPECT_FALSE(scheduler_.scheduled_);
50 EXPECT_EQ(0, scheduler_.last_interval_); 50 EXPECT_EQ(0, scheduler_.last_interval_);
51 EXPECT_EQ(0, scheduler_.poll_interval_);
51 } 52 }
52 53
53 virtual void TearDown() { 54 virtual void TearDown() {
54 test_ = NULL; 55 test_ = NULL;
55 loop_ = NULL; 56 loop_ = NULL;
56 } 57 }
57 58
58 static gboolean SourceCallback(gpointer data) { 59 static gboolean SourceCallback(gpointer data) {
59 g_main_loop_quit(test_->loop_); 60 g_main_loop_quit(test_->loop_);
60 // Forwards the call to the function mock so that expectations can be set. 61 // Forwards the call to the function mock so that expectations can be set.
(...skipping 22 matching lines...) Expand all
83 TEST_F(UpdateCheckSchedulerTest, ComputeNextIntervalAndFuzzBackoffTest) { 84 TEST_F(UpdateCheckSchedulerTest, ComputeNextIntervalAndFuzzBackoffTest) {
84 int interval, fuzz; 85 int interval, fuzz;
85 attempter_.set_http_response_code(500); 86 attempter_.set_http_response_code(500);
86 int last_interval = UpdateCheckScheduler::kTimeoutPeriodic + 50; 87 int last_interval = UpdateCheckScheduler::kTimeoutPeriodic + 50;
87 scheduler_.last_interval_ = last_interval; 88 scheduler_.last_interval_ = last_interval;
88 scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz); 89 scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz);
89 EXPECT_EQ(2 * last_interval, interval); 90 EXPECT_EQ(2 * last_interval, interval);
90 EXPECT_EQ(2 * last_interval, fuzz); 91 EXPECT_EQ(2 * last_interval, fuzz);
91 92
92 attempter_.set_http_response_code(503); 93 attempter_.set_http_response_code(503);
93 last_interval = UpdateCheckScheduler::kTimeoutMaxBackoff / 2 + 1; 94 scheduler_.last_interval_ = UpdateCheckScheduler::kTimeoutMaxBackoff / 2 + 1;
94 scheduler_.last_interval_ = last_interval;
95 scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz); 95 scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz);
96 EXPECT_EQ(UpdateCheckScheduler::kTimeoutMaxBackoff, interval); 96 EXPECT_EQ(UpdateCheckScheduler::kTimeoutMaxBackoff, interval);
97 EXPECT_EQ(UpdateCheckScheduler::kTimeoutMaxBackoff, fuzz); 97 EXPECT_EQ(UpdateCheckScheduler::kTimeoutMaxBackoff, fuzz);
98 } 98 }
99 99
100 TEST_F(UpdateCheckSchedulerTest, ComputeNextIntervalAndFuzzPollTest) {
101 int interval, fuzz;
102 int poll_interval = UpdateCheckScheduler::kTimeoutPeriodic + 50;
103 scheduler_.set_poll_interval(poll_interval);
104 scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz);
105 EXPECT_EQ(poll_interval, interval);
106 EXPECT_EQ(poll_interval, fuzz);
107
108 scheduler_.set_poll_interval(UpdateCheckScheduler::kTimeoutMaxBackoff + 1);
109 scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz);
110 EXPECT_EQ(UpdateCheckScheduler::kTimeoutMaxBackoff, interval);
111 EXPECT_EQ(UpdateCheckScheduler::kTimeoutMaxBackoff, fuzz);
112
113 scheduler_.set_poll_interval(UpdateCheckScheduler::kTimeoutPeriodic - 1);
114 scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz);
115 EXPECT_EQ(UpdateCheckScheduler::kTimeoutPeriodic, interval);
116 EXPECT_EQ(UpdateCheckScheduler::kTimeoutRegularFuzz, fuzz);
117 }
118
119 TEST_F(UpdateCheckSchedulerTest, ComputeNextIntervalAndFuzzPriorityTest) {
120 int interval, fuzz;
121 attempter_.set_http_response_code(500);
122 scheduler_.last_interval_ = UpdateCheckScheduler::kTimeoutPeriodic + 50;
123 int poll_interval = UpdateCheckScheduler::kTimeoutPeriodic + 100;
124 scheduler_.set_poll_interval(poll_interval);
125 scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz);
126 EXPECT_EQ(poll_interval, interval);
127 EXPECT_EQ(poll_interval, fuzz);
128 }
129
100 TEST_F(UpdateCheckSchedulerTest, ComputeNextIntervalAndFuzzTest) { 130 TEST_F(UpdateCheckSchedulerTest, ComputeNextIntervalAndFuzzTest) {
101 int interval, fuzz; 131 int interval, fuzz;
102 scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz); 132 scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz);
103 EXPECT_EQ(UpdateCheckScheduler::kTimeoutPeriodic, interval); 133 EXPECT_EQ(UpdateCheckScheduler::kTimeoutPeriodic, interval);
104 EXPECT_EQ(UpdateCheckScheduler::kTimeoutRegularFuzz, fuzz); 134 EXPECT_EQ(UpdateCheckScheduler::kTimeoutRegularFuzz, fuzz);
105 } 135 }
106 136
107 TEST_F(UpdateCheckSchedulerTest, GTimeoutAddSecondsTest) { 137 TEST_F(UpdateCheckSchedulerTest, GTimeoutAddSecondsTest) {
108 loop_ = g_main_loop_new(g_main_context_default(), FALSE); 138 loop_ = g_main_loop_new(g_main_context_default(), FALSE);
109 // Invokes the actual GLib wrapper method rather than the subclass mock. 139 // Invokes the actual GLib wrapper method rather than the subclass mock.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 scheduler_.SetUpdateStatus(UPDATE_STATUS_DOWNLOADING); 260 scheduler_.SetUpdateStatus(UPDATE_STATUS_DOWNLOADING);
231 } 261 }
232 262
233 TEST_F(UpdateCheckSchedulerTest, StaticCheckTest) { 263 TEST_F(UpdateCheckSchedulerTest, StaticCheckTest) {
234 scheduler_.scheduled_ = true; 264 scheduler_.scheduled_ = true;
235 EXPECT_CALL(attempter_, Update("", "")).Times(1); 265 EXPECT_CALL(attempter_, Update("", "")).Times(1);
236 UpdateCheckSchedulerUnderTest::StaticCheck(&scheduler_); 266 UpdateCheckSchedulerUnderTest::StaticCheck(&scheduler_);
237 } 267 }
238 268
239 } // namespace chromeos_update_engine 269 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « update_check_scheduler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698