summaryrefslogtreecommitdiffstats
path: root/sync/sessions/sync_session_unittest.cc
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-15 17:59:48 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-15 17:59:48 +0000
commit79dc04cce3973949e5ad5effa8b634aaf5e25c2b (patch)
tree518abd7ca489e06c759048dcc80388d94e502fc0 /sync/sessions/sync_session_unittest.cc
parent80771de8ce0c3f13c041cb03853174b95461a151 (diff)
downloadchromium_src-79dc04cce3973949e5ad5effa8b634aaf5e25c2b.zip
chromium_src-79dc04cce3973949e5ad5effa8b634aaf5e25c2b.tar.gz
chromium_src-79dc04cce3973949e5ad5effa8b634aaf5e25c2b.tar.bz2
Remove routing_info and workers from SyncSession
For all outward appearances, the SyncSession's workers and routing info will always precisely mirror those found in the SyncSessionContext. It is equivalent, and much simpler, to grab the latest routing info from the context wherever it's needed. Any SyncSession that makes it to a sync cycle will either have been initialized with the SyncSessionContext's routing info and workers, or Coalesced (set union) and Rebased (set intersection) with the SyncSessionContext's routing info and workers to the point where it's effectively equivalent to copying the context's data. Much of the logic to implement this book-keeping has been simplified in this patch. Configure mode is an important exception. While configuring, we would attempt to keep all currently enabled types enabled in the SyncSessionContext, while passing a restricted amount of routing info the the SyncSession. It turns out that it's not necessary to allow the SyncSessionContext and SyncSession routing info diverge in this case; it's OK to set the context's routing info to the restricted routes. In addition to trimming the session's routing info and workers list, RebaseRoutingInfoWithLatest was also responsible for trimming the list of notification hints to match the set of currently enabled types. This is redundant because the code in DownloadUpdatesCommand performs the same filtering using the same routing info. RebaseRoutingInfoWithLatest had no remaining useful features, so it was removed entirely. The Coalesce function still exists in a reduced form to handle merge sources between sessions. Its name and signature have been changed to reflect its new responsibilities. Without its own copy of the workers and routing info, the SyncSessionContext can no longer easily calculate the set of enabled groups. Fortunately, that information is only accessed by a single test case. The relevant code was moved into this test case. BUG=175024 Review URL: https://chromiumcodereview.appspot.com/12225091 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182756 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/sessions/sync_session_unittest.cc')
-rw-r--r--sync/sessions/sync_session_unittest.cc225
1 files changed, 6 insertions, 219 deletions
diff --git a/sync/sessions/sync_session_unittest.cc b/sync/sessions/sync_session_unittest.cc
index 8044113..008e893 100644
--- a/sync/sessions/sync_session_unittest.cc
+++ b/sync/sessions/sync_session_unittest.cc
@@ -33,10 +33,7 @@ class SyncSessionTest : public testing::Test,
SyncSessionTest() : controller_invocations_allowed_(false) {}
SyncSession* MakeSession() {
- std::vector<ModelSafeWorker*> workers;
- GetWorkers(&workers);
- return new SyncSession(context_.get(), this, SyncSourceInfo(),
- routes_, workers);
+ return new SyncSession(context_.get(), this, SyncSourceInfo());
}
virtual void SetUp() {
@@ -142,24 +139,6 @@ class SyncSessionTest : public testing::Test,
scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_;
};
-TEST_F(SyncSessionTest, EnabledGroupsEmpty) {
- routes_.clear();
- workers_.clear();
- scoped_ptr<SyncSession> session(MakeSession());
- std::set<ModelSafeGroup> expected_enabled_groups;
- expected_enabled_groups.insert(GROUP_PASSIVE);
- EXPECT_EQ(expected_enabled_groups, session->GetEnabledGroups());
-}
-
-TEST_F(SyncSessionTest, EnabledGroups) {
- scoped_ptr<SyncSession> session(MakeSession());
- std::set<ModelSafeGroup> expected_enabled_groups;
- expected_enabled_groups.insert(GROUP_PASSIVE);
- expected_enabled_groups.insert(GROUP_UI);
- expected_enabled_groups.insert(GROUP_DB);
- EXPECT_EQ(expected_enabled_groups, session->GetEnabledGroups());
-}
-
TEST_F(SyncSessionTest, SetWriteTransaction) {
TestDirectorySetterUpper dir_maker;
dir_maker.SetUp();
@@ -206,9 +185,7 @@ TEST_F(SyncSessionTest, MoreToDownloadIfGotNoChangesRemaining) {
EXPECT_TRUE(status()->download_updates_succeeded());
}
-TEST_F(SyncSessionTest, Coalesce) {
- std::vector<ModelSafeWorker*> workers_one, workers_two;
- ModelSafeRoutingInfo routes_one, routes_two;
+TEST_F(SyncSessionTest, CoalesceSources) {
ModelTypeInvalidationMap one_type =
ModelTypeSetToInvalidationMap(
ParamsMeaningJustOneEnabledType(),
@@ -220,204 +197,14 @@ TEST_F(SyncSessionTest, Coalesce) {
SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type);
SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types);
- scoped_refptr<ModelSafeWorker> passive_worker(
- new FakeModelWorker(GROUP_PASSIVE));
- scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB));
- scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI));
- workers_one.push_back(passive_worker);
- workers_one.push_back(db_worker);
- workers_two.push_back(passive_worker);
- workers_two.push_back(db_worker);
- workers_two.push_back(ui_worker);
- routes_one[AUTOFILL] = GROUP_DB;
- routes_two[AUTOFILL] = GROUP_DB;
- routes_two[BOOKMARKS] = GROUP_UI;
- SyncSession one(context_.get(), this, source_one, routes_one, workers_one);
- SyncSession two(context_.get(), this, source_two, routes_two, workers_two);
-
- std::set<ModelSafeGroup> expected_enabled_groups_one;
- expected_enabled_groups_one.insert(GROUP_PASSIVE);
- expected_enabled_groups_one.insert(GROUP_DB);
-
- std::set<ModelSafeGroup> expected_enabled_groups_two;
- expected_enabled_groups_two.insert(GROUP_PASSIVE);
- expected_enabled_groups_two.insert(GROUP_DB);
- expected_enabled_groups_two.insert(GROUP_UI);
-
- EXPECT_EQ(expected_enabled_groups_one, one.GetEnabledGroups());
- EXPECT_EQ(expected_enabled_groups_two, two.GetEnabledGroups());
-
- one.Coalesce(two);
-
- EXPECT_EQ(expected_enabled_groups_two, one.GetEnabledGroups());
- EXPECT_EQ(expected_enabled_groups_two, two.GetEnabledGroups());
-
- EXPECT_EQ(two.source().updates_source, one.source().updates_source);
- EXPECT_THAT(all_types, Eq(one.source().types));
- std::vector<ModelSafeWorker*>::const_iterator it_db =
- std::find(one.workers().begin(), one.workers().end(), db_worker);
- std::vector<ModelSafeWorker*>::const_iterator it_ui =
- std::find(one.workers().begin(), one.workers().end(), ui_worker);
- EXPECT_NE(it_db, one.workers().end());
- EXPECT_NE(it_ui, one.workers().end());
- EXPECT_EQ(routes_two, one.routing_info());
-}
-
-TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) {
- std::vector<ModelSafeWorker*> workers_one, workers_two;
- ModelSafeRoutingInfo routes_one, routes_two;
- ModelTypeInvalidationMap one_type =
- ModelTypeSetToInvalidationMap(
- ParamsMeaningJustOneEnabledType(),
- std::string());
- ModelTypeInvalidationMap all_types =
- ModelTypeSetToInvalidationMap(
- ParamsMeaningAllEnabledTypes(),
- std::string());
- SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type);
- SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types);
+ SyncSession session(context_.get(), this, source_one);
- scoped_refptr<ModelSafeWorker> passive_worker(
- new FakeModelWorker(GROUP_PASSIVE));
- scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB));
- scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI));
- workers_one.push_back(passive_worker);
- workers_one.push_back(db_worker);
- workers_two.push_back(passive_worker);
- workers_two.push_back(db_worker);
- workers_two.push_back(ui_worker);
- routes_one[AUTOFILL] = GROUP_DB;
- routes_two[AUTOFILL] = GROUP_DB;
- routes_two[BOOKMARKS] = GROUP_UI;
- SyncSession one(context_.get(), this, source_one, routes_one, workers_one);
- SyncSession two(context_.get(), this, source_two, routes_two, workers_two);
-
- std::set<ModelSafeGroup> expected_enabled_groups_one;
- expected_enabled_groups_one.insert(GROUP_PASSIVE);
- expected_enabled_groups_one.insert(GROUP_DB);
-
- std::set<ModelSafeGroup> expected_enabled_groups_two;
- expected_enabled_groups_two.insert(GROUP_PASSIVE);
- expected_enabled_groups_two.insert(GROUP_DB);
- expected_enabled_groups_two.insert(GROUP_UI);
-
- EXPECT_EQ(expected_enabled_groups_one, one.GetEnabledGroups());
- EXPECT_EQ(expected_enabled_groups_two, two.GetEnabledGroups());
-
- two.RebaseRoutingInfoWithLatest(one.routing_info(), one.workers());
-
- EXPECT_EQ(expected_enabled_groups_one, one.GetEnabledGroups());
- EXPECT_EQ(expected_enabled_groups_one, two.GetEnabledGroups());
-
- // Make sure the source has not been touched.
- EXPECT_EQ(two.source().updates_source,
- sync_pb::GetUpdatesCallerInfo::LOCAL);
-
- // Make sure the payload is reduced to one.
- EXPECT_THAT(one_type, Eq(two.source().types));
-
- // Make sure the workers are udpated.
- std::vector<ModelSafeWorker*>::const_iterator it_db =
- std::find(two.workers().begin(), two.workers().end(), db_worker);
- std::vector<ModelSafeWorker*>::const_iterator it_ui =
- std::find(two.workers().begin(), two.workers().end(), ui_worker);
- EXPECT_NE(it_db, two.workers().end());
- EXPECT_EQ(it_ui, two.workers().end());
- EXPECT_EQ(two.workers().size(), 2U);
-
- // Make sure the model safe routing info is reduced to one type.
- ModelSafeRoutingInfo::const_iterator it =
- two.routing_info().find(AUTOFILL);
- // Note that attempting to use EXPECT_NE would fail for an Android build due
- // to seeming incompatibility with gtest and stlport.
- EXPECT_TRUE(it != two.routing_info().end());
- EXPECT_EQ(it->second, GROUP_DB);
- EXPECT_EQ(two.routing_info().size(), 1U);
-}
+ session.CoalesceSources(source_two);
-TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) {
- std::vector<ModelSafeWorker*> workers_first, workers_second;
- ModelSafeRoutingInfo routes_first, routes_second;
- ModelTypeInvalidationMap all_types =
- ModelTypeSetToInvalidationMap(
- ParamsMeaningAllEnabledTypes(),
- std::string());
- SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC,
- all_types);
- SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL,
- all_types);
-
- scoped_refptr<ModelSafeWorker> passive_worker(
- new FakeModelWorker(GROUP_PASSIVE));
- scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB));
- scoped_refptr<FakeModelWorker> ui_worker(new FakeModelWorker(GROUP_UI));
- workers_first.push_back(passive_worker);
- workers_first.push_back(db_worker);
- workers_first.push_back(ui_worker);
- workers_second.push_back(passive_worker);
- workers_second.push_back(db_worker);
- workers_second.push_back(ui_worker);
- routes_first[AUTOFILL] = GROUP_DB;
- routes_first[BOOKMARKS] = GROUP_UI;
- routes_second[AUTOFILL] = GROUP_DB;
- routes_second[BOOKMARKS] = GROUP_UI;
- SyncSession first(context_.get(), this, source_first, routes_first,
- workers_first);
- SyncSession second(context_.get(), this, source_second, routes_second,
- workers_second);
-
- std::set<ModelSafeGroup> expected_enabled_groups;
- expected_enabled_groups.insert(GROUP_PASSIVE);
- expected_enabled_groups.insert(GROUP_DB);
- expected_enabled_groups.insert(GROUP_UI);
-
- EXPECT_EQ(expected_enabled_groups, first.GetEnabledGroups());
- EXPECT_EQ(expected_enabled_groups, second.GetEnabledGroups());
-
- second.RebaseRoutingInfoWithLatest(first.routing_info(), first.workers());
-
- EXPECT_EQ(expected_enabled_groups, first.GetEnabledGroups());
- EXPECT_EQ(expected_enabled_groups, second.GetEnabledGroups());
-
- // Make sure the source has not been touched.
- EXPECT_EQ(second.source().updates_source,
- sync_pb::GetUpdatesCallerInfo::LOCAL);
-
- // Make sure our payload is still the same.
- EXPECT_THAT(all_types, Eq(second.source().types));
-
- // Make sure the workers are still the same.
- std::vector<ModelSafeWorker*>::const_iterator it_passive =
- std::find(second.workers().begin(), second.workers().end(),
- passive_worker);
- std::vector<ModelSafeWorker*>::const_iterator it_db =
- std::find(second.workers().begin(), second.workers().end(), db_worker);
- std::vector<ModelSafeWorker*>::const_iterator it_ui =
- std::find(second.workers().begin(), second.workers().end(), ui_worker);
- EXPECT_NE(it_passive, second.workers().end());
- EXPECT_NE(it_db, second.workers().end());
- EXPECT_NE(it_ui, second.workers().end());
- EXPECT_EQ(second.workers().size(), 3U);
-
- // Make sure the model safe routing info is reduced to first type.
- ModelSafeRoutingInfo::const_iterator it1 =
- second.routing_info().find(AUTOFILL);
- ModelSafeRoutingInfo::const_iterator it2 =
- second.routing_info().find(BOOKMARKS);
-
- // Note that attempting to use EXPECT_NE would fail for an Android build due
- // to seeming incompatibility with gtest and stlport.
- EXPECT_TRUE(it1 != second.routing_info().end());
- EXPECT_EQ(it1->second, GROUP_DB);
-
- // Note that attempting to use EXPECT_NE would fail for an Android build due
- // to seeming incompatibility with gtest and stlport.
- EXPECT_TRUE(it2 != second.routing_info().end());
- EXPECT_EQ(it2->second, GROUP_UI);
- EXPECT_EQ(second.routing_info().size(), 2U);
+ EXPECT_EQ(source_two.updates_source, session.source().updates_source);
+ EXPECT_THAT(all_types, Eq(session.source().types));
}
-
TEST_F(SyncSessionTest, MakeTypeInvalidationMapFromBitSet) {
ModelTypeSet types;
std::string payload = "test";