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

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

Issue 13422003: sync: Refactor job ownership in SyncScheduler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Attempt to fix subtle problem with nudge-in-backoff handling Created 7 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "sync/engine/sync_session_job.h" 5 #include "sync/engine/sync_session_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "sync/internal_api/public/base/model_type_invalidation_map.h" 10 #include "sync/internal_api/public/base/model_type_invalidation_map.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 114
115 private: 115 private:
116 scoped_ptr<sessions::SyncSessionContext> context_; 116 scoped_ptr<sessions::SyncSessionContext> context_;
117 std::vector<scoped_refptr<ModelSafeWorker> > workers_; 117 std::vector<scoped_refptr<ModelSafeWorker> > workers_;
118 MockDelegate delegate_; 118 MockDelegate delegate_;
119 ModelSafeRoutingInfo routes_; 119 ModelSafeRoutingInfo routes_;
120 bool config_params_callback_invoked_; 120 bool config_params_callback_invoked_;
121 }; 121 };
122 122
123 TEST_F(SyncSessionJobTest, Clone) {
124 SyncSessionJob job1(SyncSessionJob::NUDGE, TimeTicks::Now(),
125 MakeSourceInfo(), ConfigurationParams());
126
127 scoped_ptr<SyncSession> session1 = MakeSession().Pass();
128 sessions::test_util::SimulateSuccess(session1.get(),
129 job1.start_step(),
130 job1.end_step());
131 job1.Finish(false, session1.get());
132 ModelSafeRoutingInfo new_routes;
133 new_routes[AUTOFILL] = GROUP_PASSIVE;
134 context()->set_routing_info(new_routes);
135 scoped_ptr<SyncSessionJob> clone1 = job1.Clone();
136
137 ExpectClones(&job1, clone1.get());
138
139 context()->set_routing_info(routes());
140 scoped_ptr<SyncSession> session2 = MakeSession().Pass();
141 sessions::test_util::SimulateSuccess(session2.get(),
142 clone1->start_step(),
143 clone1->end_step());
144 clone1->Finish(false, session2.get());
145 scoped_ptr<SyncSessionJob> clone2 = clone1->Clone();
146
147 ExpectClones(clone1.get(), clone2.get());
148
149 clone1.reset();
150 ExpectClones(&job1, clone2.get());
151 }
152
153 TEST_F(SyncSessionJobTest, CloneAfterEarlyExit) {
154 scoped_ptr<SyncSession> session = MakeSession().Pass();
155 SyncSessionJob job1(SyncSessionJob::NUDGE, TimeTicks::Now(),
156 MakeSourceInfo(), ConfigurationParams());
157 job1.Finish(true, session.get());
158 scoped_ptr<SyncSessionJob> job2 = job1.Clone();
159 ExpectClones(&job1, job2.get());
160 }
161
162 // Tests interaction between Finish and sync cycle success / failure.
163 TEST_F(SyncSessionJobTest, Finish) {
164 SyncSessionJob job1(SyncSessionJob::NUDGE, TimeTicks::Now(),
165 MakeSourceInfo(), ConfigurationParams());
166
167 scoped_ptr<SyncSession> session1 = MakeSession().Pass();
168 sessions::test_util::SimulateSuccess(session1.get(),
169 job1.start_step(),
170 job1.end_step());
171 EXPECT_TRUE(job1.Finish(false /* early_exit */, session1.get()));
172
173 scoped_ptr<SyncSessionJob> job2 = job1.Clone();
174 scoped_ptr<SyncSession> session2 = MakeSession().Pass();
175 sessions::test_util::SimulateConnectionFailure(session2.get(),
176 job2->start_step(),
177 job2->end_step());
178 EXPECT_FALSE(job2->Finish(false, session2.get()));
179 }
180
181 TEST_F(SyncSessionJobTest, FinishCallsReadyTask) { 123 TEST_F(SyncSessionJobTest, FinishCallsReadyTask) {
182 ConfigurationParams params; 124 ConfigurationParams params;
183 params.ready_task = base::Bind( 125 params.ready_task = base::Bind(
184 &SyncSessionJobTest::ConfigurationParamsCallback, 126 &SyncSessionJobTest::ConfigurationParamsCallback,
185 base::Unretained(this)); 127 base::Unretained(this));
186 128
187 sessions::SyncSourceInfo info( 129 sessions::SyncSourceInfo info(
188 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, 130 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
189 ModelTypeInvalidationMap()); 131 ModelTypeInvalidationMap());
190 scoped_ptr<SyncSession> session( 132 scoped_ptr<SyncSession> session(
(...skipping 24 matching lines...) Expand all
215 157
216 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now(), 158 SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now(),
217 source_one, ConfigurationParams()); 159 source_one, ConfigurationParams());
218 160
219 job.CoalesceSources(source_two); 161 job.CoalesceSources(source_two);
220 162
221 EXPECT_EQ(source_two.updates_source, job.source_info().updates_source); 163 EXPECT_EQ(source_two.updates_source, job.source_info().updates_source);
222 } 164 }
223 165
224 } // namespace syncer 166 } // namespace syncer
OLDNEW
« sync/engine/sync_scheduler_impl.cc ('K') | « sync/engine/sync_session_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698