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

Side by Side Diff: sync/internal_api/attachments/task_queue_unittest.cc

Issue 569463002: Make AttachmentServiceImpl clear backoff when reconnected to network. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master. Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium 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 "sync/internal_api/public/attachments/task_queue.h" 5 #include "sync/internal_api/public/attachments/task_queue.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 // See that Retry works as expected. 99 // See that Retry works as expected.
100 TEST_F(TaskQueueTest, Retry) { 100 TEST_F(TaskQueueTest, Retry) {
101 scoped_ptr<base::MockTimer> timer_to_pass(new base::MockTimer(false, false)); 101 scoped_ptr<base::MockTimer> timer_to_pass(new base::MockTimer(false, false));
102 base::MockTimer* mock_timer = timer_to_pass.get(); 102 base::MockTimer* mock_timer = timer_to_pass.get();
103 queue_->SetTimerForTest(timer_to_pass.PassAs<base::Timer>()); 103 queue_->SetTimerForTest(timer_to_pass.PassAs<base::Timer>());
104 104
105 // 1st attempt. 105 // 1st attempt.
106 queue_->AddToQueue(1); 106 queue_->AddToQueue(1);
107 ASSERT_TRUE(mock_timer->IsRunning()); 107 ASSERT_TRUE(mock_timer->IsRunning());
108 ASSERT_EQ(TimeDelta(), mock_timer->GetCurrentDelay()); 108 ASSERT_EQ(kZero, mock_timer->GetCurrentDelay());
109 TimeDelta last_delay = mock_timer->GetCurrentDelay(); 109 TimeDelta last_delay = mock_timer->GetCurrentDelay();
110 mock_timer->Fire(); 110 mock_timer->Fire();
111 RunLoop(); 111 RunLoop();
112 112
113 // 2nd attempt. 113 // 2nd attempt.
114 ASSERT_FALSE(mock_timer->IsRunning()); 114 ASSERT_FALSE(mock_timer->IsRunning());
115 ASSERT_EQ(1U, dispatched_.size()); 115 ASSERT_EQ(1U, dispatched_.size());
116 EXPECT_EQ(1, dispatched_.front()); 116 EXPECT_EQ(1, dispatched_.front());
117 dispatched_.clear(); 117 dispatched_.clear();
118 queue_->MarkAsFailed(1); 118 queue_->MarkAsFailed(1);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 187
188 ASSERT_EQ(1U, dispatched_.size()); 188 ASSERT_EQ(1U, dispatched_.size());
189 EXPECT_EQ(1, dispatched_.front()); 189 EXPECT_EQ(1, dispatched_.front());
190 dispatched_.clear(); 190 dispatched_.clear();
191 queue_->Cancel(1); 191 queue_->Cancel(1);
192 RunLoop(); 192 RunLoop();
193 193
194 ASSERT_TRUE(dispatched_.empty()); 194 ASSERT_TRUE(dispatched_.empty());
195 } 195 }
196 196
197 // See that ResetBackoff resets the backoff delay.
198 TEST_F(TaskQueueTest, ResetBackoff) {
199 scoped_ptr<base::MockTimer> timer_to_pass(new base::MockTimer(false, false));
200 base::MockTimer* mock_timer = timer_to_pass.get();
201 queue_->SetTimerForTest(timer_to_pass.PassAs<base::Timer>());
202
203 // Add an item, mark it as failed, re-add it and see that we now have a
204 // backoff delay.
205 queue_->AddToQueue(1);
206 ASSERT_TRUE(mock_timer->IsRunning());
207 ASSERT_EQ(kZero, mock_timer->GetCurrentDelay());
208 mock_timer->Fire();
209 RunLoop();
210 ASSERT_FALSE(mock_timer->IsRunning());
211 ASSERT_EQ(1U, dispatched_.size());
212 EXPECT_EQ(1, dispatched_.front());
213 dispatched_.clear();
214 queue_->MarkAsFailed(1);
215 queue_->AddToQueue(1);
216 ASSERT_TRUE(mock_timer->IsRunning());
217 EXPECT_GT(mock_timer->GetCurrentDelay(), kZero);
218 EXPECT_LE(mock_timer->GetCurrentDelay(), TimeDelta::FromMinutes(1));
219
220 // Call ResetBackoff and see that there is no longer a delay.
221 queue_->ResetBackoff();
222 ASSERT_TRUE(mock_timer->IsRunning());
223 ASSERT_EQ(kZero, mock_timer->GetCurrentDelay());
224 mock_timer->Fire();
225 RunLoop();
226 ASSERT_FALSE(mock_timer->IsRunning());
227 ASSERT_EQ(1U, dispatched_.size());
228 EXPECT_EQ(1, dispatched_.front());
229 dispatched_.clear();
230 queue_->MarkAsSucceeded(1);
231 }
232
197 } // namespace syncer 233 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698