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

Side by Side Diff: sync/engine/download_unittest.cc

Issue 146113003: sync: GU retry with less explicit TimeTicks logic (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update NudgeTracker before normal mode transition cycle Created 6 years, 10 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 | « sync/engine/download.cc ('k') | sync/engine/sync_scheduler_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/engine/download.h" 5 #include "sync/engine/download.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "sync/engine/sync_directory_update_handler.h" 9 #include "sync/engine/sync_directory_update_handler.h"
10 #include "sync/internal_api/public/base/model_type_test_util.h" 10 #include "sync/internal_api/public/base/model_type_test_util.h"
11 #include "sync/protocol/sync.pb.h" 11 #include "sync/protocol/sync.pb.h"
12 #include "sync/sessions/debug_info_getter.h" 12 #include "sync/sessions/debug_info_getter.h"
13 #include "sync/sessions/nudge_tracker.h" 13 #include "sync/sessions/nudge_tracker.h"
14 #include "sync/sessions/status_controller.h" 14 #include "sync/sessions/status_controller.h"
15 #include "sync/syncable/directory.h" 15 #include "sync/syncable/directory.h"
16 #include "sync/test/engine/fake_model_worker.h" 16 #include "sync/test/engine/fake_model_worker.h"
17 #include "sync/test/engine/test_directory_setter_upper.h" 17 #include "sync/test/engine/test_directory_setter_upper.h"
18 #include "sync/test/sessions/mock_debug_info_getter.h" 18 #include "sync/test/sessions/mock_debug_info_getter.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 namespace syncer { 21 namespace syncer {
22 22
23 using sessions::MockDebugInfoGetter; 23 using sessions::MockDebugInfoGetter;
24 24
25 // A test fixture for tests exercising download updates functions. 25 // A test fixture for tests exercising download updates functions.
26 class DownloadUpdatesTest : public ::testing::Test { 26 class DownloadUpdatesTest : public ::testing::Test {
27 protected: 27 protected:
28 DownloadUpdatesTest() : update_handler_deleter_(&update_handler_map_) {} 28 DownloadUpdatesTest() :
29 kTestStartTime(base::TimeTicks::Now()),
30 update_handler_deleter_(&update_handler_map_) {}
29 31
30 virtual void SetUp() { 32 virtual void SetUp() {
31 dir_maker_.SetUp(); 33 dir_maker_.SetUp();
32 34
33 AddUpdateHandler(AUTOFILL, GROUP_DB); 35 AddUpdateHandler(AUTOFILL, GROUP_DB);
34 AddUpdateHandler(BOOKMARKS, GROUP_UI); 36 AddUpdateHandler(BOOKMARKS, GROUP_UI);
35 AddUpdateHandler(PREFERENCES, GROUP_UI); 37 AddUpdateHandler(PREFERENCES, GROUP_UI);
36 } 38 }
37 39
38 virtual void TearDown() { 40 virtual void TearDown() {
(...skipping 18 matching lines...) Expand all
57 for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { 59 for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) {
58 sync_pb::DataTypeProgressMarker* marker = 60 sync_pb::DataTypeProgressMarker* marker =
59 response->add_new_progress_marker(); 61 response->add_new_progress_marker();
60 marker->set_data_type_id(GetSpecificsFieldNumberFromModelType(it.Get())); 62 marker->set_data_type_id(GetSpecificsFieldNumberFromModelType(it.Get()));
61 marker->set_token("foobarbaz"); 63 marker->set_token("foobarbaz");
62 } 64 }
63 65
64 response->set_changes_remaining(0); 66 response->set_changes_remaining(0);
65 } 67 }
66 68
69 const base::TimeTicks kTestStartTime;
70
67 private: 71 private:
68 void AddUpdateHandler(ModelType type, ModelSafeGroup group) { 72 void AddUpdateHandler(ModelType type, ModelSafeGroup group) {
69 DCHECK(directory()); 73 DCHECK(directory());
70 74
71 proto_request_types_.Put(type); 75 proto_request_types_.Put(type);
72 76
73 scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(group); 77 scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(group);
74 SyncDirectoryUpdateHandler* handler = 78 SyncDirectoryUpdateHandler* handler =
75 new SyncDirectoryUpdateHandler(directory(), type, worker); 79 new SyncDirectoryUpdateHandler(directory(), type, worker);
76 update_handler_map_.insert(std::make_pair(type, handler)); 80 update_handler_map_.insert(std::make_pair(type, handler));
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( 241 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber(
238 gu_msg.from_progress_marker(i).data_type_id()); 242 gu_msg.from_progress_marker(i).data_type_id());
239 progress_types.Put(type); 243 progress_types.Put(type);
240 } 244 }
241 EXPECT_TRUE(proto_request_types().Equals(progress_types)); 245 EXPECT_TRUE(proto_request_types().Equals(progress_types));
242 } 246 }
243 247
244 TEST_F(DownloadUpdatesTest, NudgeWithRetryTest) { 248 TEST_F(DownloadUpdatesTest, NudgeWithRetryTest) {
245 sessions::NudgeTracker nudge_tracker; 249 sessions::NudgeTracker nudge_tracker;
246 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); 250 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS));
247 nudge_tracker.set_next_retry_time( 251
248 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1)); 252 // Schedule a retry.
253 base::TimeTicks t1 = kTestStartTime;
254 nudge_tracker.SetNextRetryTime(t1);
255
256 // Get the nudge tracker to think the retry is due.
257 nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1));
249 258
250 sync_pb::ClientToServerMessage msg; 259 sync_pb::ClientToServerMessage msg;
251 download::BuildNormalDownloadUpdatesImpl(proto_request_types(), 260 download::BuildNormalDownloadUpdatesImpl(proto_request_types(),
252 get_updates_processor(), 261 get_updates_processor(),
253 nudge_tracker, 262 nudge_tracker,
254 msg.mutable_get_updates()); 263 msg.mutable_get_updates());
255 EXPECT_TRUE(msg.get_updates().is_retry()); 264 EXPECT_TRUE(msg.get_updates().is_retry());
256 } 265 }
257 266
258 // Verify that a bogus response message is detected. 267 // Verify that a bogus response message is detected.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { 342 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) {
334 sync_pb::DebugInfo debug_info; 343 sync_pb::DebugInfo debug_info;
335 AddDebugEvent(); 344 AddDebugEvent();
336 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); 345 download::CopyClientDebugInfo(debug_info_getter(), &debug_info);
337 EXPECT_EQ(1, debug_info.events_size()); 346 EXPECT_EQ(1, debug_info.events_size());
338 download::CopyClientDebugInfo(debug_info_getter(), &debug_info); 347 download::CopyClientDebugInfo(debug_info_getter(), &debug_info);
339 EXPECT_EQ(1, debug_info.events_size()); 348 EXPECT_EQ(1, debug_info.events_size());
340 } 349 }
341 350
342 } // namespace syncer 351 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/download.cc ('k') | sync/engine/sync_scheduler_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698