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

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

Issue 23809005: sync: Implement per-type GetCommitIds (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unnecessary whitespace Created 7 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
11 #include <map> 11 #include <map>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/bind_helpers.h" 16 #include "base/bind_helpers.h"
17 #include "base/callback.h" 17 #include "base/callback.h"
18 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
19 #include "base/location.h" 19 #include "base/location.h"
20 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
21 #include "base/message_loop/message_loop.h" 21 #include "base/message_loop/message_loop.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "sync/engine/get_commit_ids_command.h" 26 #include "sync/engine/get_commit_ids.h"
27 #include "sync/engine/net/server_connection_manager.h" 27 #include "sync/engine/net/server_connection_manager.h"
28 #include "sync/engine/process_updates_command.h" 28 #include "sync/engine/process_updates_command.h"
29 #include "sync/engine/sync_scheduler_impl.h" 29 #include "sync/engine/sync_scheduler_impl.h"
30 #include "sync/engine/syncer.h" 30 #include "sync/engine/syncer.h"
31 #include "sync/engine/syncer_proto_util.h" 31 #include "sync/engine/syncer_proto_util.h"
32 #include "sync/engine/traffic_recorder.h" 32 #include "sync/engine/traffic_recorder.h"
33 #include "sync/internal_api/public/base/model_type.h" 33 #include "sync/internal_api/public/base/model_type.h"
34 #include "sync/internal_api/public/engine/model_safe_worker.h" 34 #include "sync/internal_api/public/engine/model_safe_worker.h"
35 #include "sync/protocol/bookmark_specifics.pb.h" 35 #include "sync/protocol/bookmark_specifics.pb.h"
36 #include "sync/protocol/nigori_specifics.pb.h" 36 #include "sync/protocol/nigori_specifics.pb.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 380 }
381 } 381 }
382 test++; 382 test++;
383 } 383 }
384 } 384 }
385 SyncShareNudge(); 385 SyncShareNudge();
386 ASSERT_TRUE(expected_positions.size() == 386 ASSERT_TRUE(expected_positions.size() ==
387 mock_server_->committed_ids().size()); 387 mock_server_->committed_ids().size());
388 // If this test starts failing, be aware other sort orders could be valid. 388 // If this test starts failing, be aware other sort orders could be valid.
389 for (size_t i = 0; i < expected_positions.size(); ++i) { 389 for (size_t i = 0; i < expected_positions.size(); ++i) {
390 SCOPED_TRACE(i);
390 EXPECT_EQ(1u, expected_positions.count(i)); 391 EXPECT_EQ(1u, expected_positions.count(i));
391 EXPECT_TRUE(expected_positions[i] == mock_server_->committed_ids()[i]); 392 EXPECT_EQ(expected_positions[i], mock_server_->committed_ids()[i]);
392 } 393 }
393 } 394 }
394 395
395 void DoTruncationTest(const vector<int64>& unsynced_handle_view, 396 void DoTruncationTest(const vector<int64>& unsynced_handle_view,
396 const vector<int64>& expected_handle_order) { 397 const vector<int64>& expected_handle_order) {
397 for (size_t limit = expected_handle_order.size() + 2; limit > 0; --limit) { 398 for (size_t limit = expected_handle_order.size() + 2; limit > 0; --limit) {
398 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 399 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
399 400
400 ModelSafeRoutingInfo routes; 401 ModelSafeRoutingInfo routes;
401 GetModelSafeRoutingInfo(&routes); 402 GetModelSafeRoutingInfo(&routes);
402 ModelTypeSet types = GetRoutingInfoTypes(routes); 403 ModelTypeSet types = GetRoutingInfoTypes(routes);
403 sessions::OrderedCommitSet output_set(routes); 404 sessions::OrderedCommitSet output_set(routes);
404 GetCommitIdsCommand command(&wtrans, types, limit, &output_set); 405 GetCommitIds(&wtrans, types, limit, &output_set);
405 std::set<int64> ready_unsynced_set;
406 command.FilterUnreadyEntries(&wtrans, types,
407 ModelTypeSet(), false,
408 unsynced_handle_view, &ready_unsynced_set);
409 command.BuildCommitIds(&wtrans, routes, ready_unsynced_set);
410 size_t truncated_size = std::min(limit, expected_handle_order.size()); 406 size_t truncated_size = std::min(limit, expected_handle_order.size());
411 ASSERT_EQ(truncated_size, output_set.Size()); 407 ASSERT_EQ(truncated_size, output_set.Size());
412 for (size_t i = 0; i < truncated_size; ++i) { 408 for (size_t i = 0; i < truncated_size; ++i) {
413 ASSERT_EQ(expected_handle_order[i], output_set.GetCommitHandleAt(i)) 409 ASSERT_EQ(expected_handle_order[i], output_set.GetCommitHandleAt(i))
414 << "At index " << i << " with batch size limited to " << limit; 410 << "At index " << i << " with batch size limited to " << limit;
415 } 411 }
416 sessions::OrderedCommitSet::Projection proj; 412 sessions::OrderedCommitSet::Projection proj;
417 proj = output_set.GetCommitIdProjection(GROUP_PASSIVE); 413 proj = output_set.GetCommitIdProjection(GROUP_PASSIVE);
418 ASSERT_EQ(truncated_size, proj.size()); 414 ASSERT_EQ(truncated_size, proj.size());
419 for (size_t i = 0; i < truncated_size; ++i) { 415 for (size_t i = 0; i < truncated_size; ++i) {
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 TEST_F(SyncerTest, TestCommitListOrderingThreeItemsTall) { 1175 TEST_F(SyncerTest, TestCommitListOrderingThreeItemsTall) {
1180 CommitOrderingTest items[] = { 1176 CommitOrderingTest items[] = {
1181 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)}, 1177 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)},
1182 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)}, 1178 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)},
1183 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)}, 1179 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)},
1184 CommitOrderingTest::MakeLastCommitItem(), 1180 CommitOrderingTest::MakeLastCommitItem(),
1185 }; 1181 };
1186 RunCommitOrderingTest(items); 1182 RunCommitOrderingTest(items);
1187 } 1183 }
1188 1184
1185 TEST_F(SyncerTest, TestCommitListOrderingFourItemsTall) {
1186 CommitOrderingTest items[] = {
1187 {3, ids_.FromNumber(-2003), ids_.FromNumber(-2002)},
1188 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)},
1189 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)},
1190 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)},
1191 CommitOrderingTest::MakeLastCommitItem(),
1192 };
1193 RunCommitOrderingTest(items);
1194 }
1195
1189 TEST_F(SyncerTest, TestCommitListOrderingThreeItemsTallLimitedSize) { 1196 TEST_F(SyncerTest, TestCommitListOrderingThreeItemsTallLimitedSize) {
1190 context_->set_max_commit_batch_size(2); 1197 context_->set_max_commit_batch_size(2);
1191 CommitOrderingTest items[] = { 1198 CommitOrderingTest items[] = {
1192 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)}, 1199 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)},
1193 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)}, 1200 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)},
1194 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)}, 1201 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)},
1195 CommitOrderingTest::MakeLastCommitItem(), 1202 CommitOrderingTest::MakeLastCommitItem(),
1196 }; 1203 };
1197 RunCommitOrderingTest(items); 1204 RunCommitOrderingTest(items);
1198 } 1205 }
(...skipping 3607 matching lines...) Expand 10 before | Expand all | Expand 10 after
4806 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); 4813 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
4807 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 4814 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
4808 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 4815 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
4809 } else { 4816 } else {
4810 EXPECT_TRUE(final_monitor_records.empty()) 4817 EXPECT_TRUE(final_monitor_records.empty())
4811 << "Should not restore records after successful bookmark commit."; 4818 << "Should not restore records after successful bookmark commit.";
4812 } 4819 }
4813 } 4820 }
4814 4821
4815 } // namespace syncer 4822 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698