Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/synchronization/waitable_event.h" | 5 #include "base/synchronization/waitable_event.h" |
| 6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
| 7 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" | 7 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" |
| 8 #include "chrome/browser/sync/engine/syncer.h" | 8 #include "chrome/browser/sync/engine/syncer.h" |
| 9 #include "chrome/browser/sync/engine/syncer_thread2.h" | 9 #include "chrome/browser/sync/engine/syncer_thread2.h" |
| 10 #include "chrome/browser/sync/sessions/test_util.h" | 10 #include "chrome/browser/sync/sessions/test_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 namespace browser_sync { | 26 namespace browser_sync { |
| 27 using sessions::SyncSession; | 27 using sessions::SyncSession; |
| 28 using sessions::SyncSessionContext; | 28 using sessions::SyncSessionContext; |
| 29 using sessions::SyncSessionSnapshot; | 29 using sessions::SyncSessionSnapshot; |
| 30 using syncable::ModelTypeBitSet; | 30 using syncable::ModelTypeBitSet; |
| 31 using sync_pb::GetUpdatesCallerInfo; | 31 using sync_pb::GetUpdatesCallerInfo; |
| 32 | 32 |
| 33 class MockSyncer : public Syncer { | 33 class MockSyncer : public Syncer { |
| 34 public: | 34 public: |
| 35 MOCK_METHOD1(SyncShare, void(sessions::SyncSession*)); | 35 MOCK_METHOD3(SyncShare, void(sessions::SyncSession*, SyncerStep, |
| 36 SyncerStep)); | |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 namespace s3 { | 39 namespace s3 { |
| 39 | 40 |
| 40 // Used when tests want to record syncing activity to examine later. | 41 // Used when tests want to record syncing activity to examine later. |
| 41 struct SyncShareRecords { | 42 struct SyncShareRecords { |
| 42 std::vector<TimeTicks> times; | 43 std::vector<TimeTicks> times; |
| 43 std::vector<linked_ptr<SyncSessionSnapshot> > snapshots; | 44 std::vector<linked_ptr<SyncSessionSnapshot> > snapshots; |
| 44 }; | 45 }; |
| 45 | 46 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 } | 177 } |
| 177 | 178 |
| 178 // Test nudge scheduling. | 179 // Test nudge scheduling. |
| 179 TEST_F(SyncerThread2Test, Nudge) { | 180 TEST_F(SyncerThread2Test, Nudge) { |
| 180 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 181 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 181 base::WaitableEvent done(false, false); | 182 base::WaitableEvent done(false, false); |
| 182 SyncShareRecords records; | 183 SyncShareRecords records; |
| 183 syncable::ModelTypeBitSet model_types; | 184 syncable::ModelTypeBitSet model_types; |
| 184 model_types[syncable::BOOKMARKS] = true; | 185 model_types[syncable::BOOKMARKS] = true; |
| 185 | 186 |
| 186 EXPECT_CALL(*syncer(), SyncShare(_)) | 187 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 187 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 188 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 188 WithArg<0>(RecordSyncShare(&records, 1U, &done)))) | 189 WithArg<0>(RecordSyncShare(&records, 1U, &done)))) |
| 189 .RetiresOnSaturation(); | 190 .RetiresOnSaturation(); |
| 190 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, model_types); | 191 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, model_types); |
| 191 done.TimedWait(timeout()); | 192 done.TimedWait(timeout()); |
| 192 | 193 |
| 193 EXPECT_EQ(1U, records.snapshots.size()); | 194 EXPECT_EQ(1U, records.snapshots.size()); |
| 194 EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(model_types, | 195 EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(model_types, |
| 195 records.snapshots[0]->source.types)); | 196 records.snapshots[0]->source.types)); |
| 196 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 197 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 197 records.snapshots[0]->source.updates_source); | 198 records.snapshots[0]->source.updates_source); |
| 198 | 199 |
| 199 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 200 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 200 SyncShareRecords records2; | 201 SyncShareRecords records2; |
| 201 model_types[syncable::BOOKMARKS] = false; | 202 model_types[syncable::BOOKMARKS] = false; |
| 202 model_types[syncable::AUTOFILL] = true; | 203 model_types[syncable::AUTOFILL] = true; |
| 203 EXPECT_CALL(*syncer(), SyncShare(_)) | 204 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 204 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 205 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 205 WithArg<0>(RecordSyncShare(&records2, 1U, &done)))); | 206 WithArg<0>(RecordSyncShare(&records2, 1U, &done)))); |
| 206 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, model_types); | 207 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, model_types); |
| 207 done.TimedWait(timeout()); | 208 done.TimedWait(timeout()); |
| 208 | 209 |
| 209 EXPECT_EQ(1U, records2.snapshots.size()); | 210 EXPECT_EQ(1U, records2.snapshots.size()); |
| 210 EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(model_types, | 211 EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(model_types, |
| 211 records2.snapshots[0]->source.types)); | 212 records2.snapshots[0]->source.types)); |
| 212 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 213 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 213 records2.snapshots[0]->source.updates_source); | 214 records2.snapshots[0]->source.updates_source); |
| 214 } | 215 } |
| 215 | 216 |
| 216 // Test that nudges are coalesced. | 217 // Test that nudges are coalesced. |
| 217 TEST_F(SyncerThread2Test, NudgeCoalescing) { | 218 TEST_F(SyncerThread2Test, NudgeCoalescing) { |
| 218 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 219 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 219 base::WaitableEvent done(false, false); | 220 base::WaitableEvent done(false, false); |
| 220 SyncShareRecords r; | 221 SyncShareRecords r; |
| 221 EXPECT_CALL(*syncer(), SyncShare(_)) | 222 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 222 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 223 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 223 WithArg<0>(RecordSyncShare(&r, 1U, &done)))); | 224 WithArg<0>(RecordSyncShare(&r, 1U, &done)))); |
| 224 syncable::ModelTypeBitSet types1, types2, types3; | 225 syncable::ModelTypeBitSet types1, types2, types3; |
| 225 types1[syncable::BOOKMARKS] = true; | 226 types1[syncable::BOOKMARKS] = true; |
| 226 types2[syncable::AUTOFILL] = true; | 227 types2[syncable::AUTOFILL] = true; |
| 227 types3[syncable::THEMES] = true; | 228 types3[syncable::THEMES] = true; |
| 228 TimeDelta delay = TimeDelta::FromMilliseconds(20); | 229 TimeDelta delay = TimeDelta::FromMilliseconds(20); |
| 229 TimeTicks optimal_time = TimeTicks::Now() + delay; | 230 TimeTicks optimal_time = TimeTicks::Now() + delay; |
| 230 syncer_thread()->ScheduleNudge(delay, NUDGE_SOURCE_UNKNOWN, types1); | 231 syncer_thread()->ScheduleNudge(delay, NUDGE_SOURCE_UNKNOWN, types1); |
| 231 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types2); | 232 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types2); |
| 232 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_NOTIFICATION, types3); | 233 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_NOTIFICATION, types3); |
| 233 done.TimedWait(timeout()); | 234 done.TimedWait(timeout()); |
| 234 | 235 |
| 235 EXPECT_EQ(1U, r.snapshots.size()); | 236 EXPECT_EQ(1U, r.snapshots.size()); |
| 236 EXPECT_GE(r.times[0], optimal_time); | 237 EXPECT_GE(r.times[0], optimal_time); |
| 237 EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(types1 | types2 | types3, | 238 EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(types1 | types2 | types3, |
| 238 r.snapshots[0]->source.types)); | 239 r.snapshots[0]->source.types)); |
| 239 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, | 240 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, |
| 240 r.snapshots[0]->source.updates_source); | 241 r.snapshots[0]->source.updates_source); |
| 241 | 242 |
| 242 SyncShareRecords r2; | 243 SyncShareRecords r2; |
| 243 EXPECT_CALL(*syncer(), SyncShare(_)) | 244 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 244 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 245 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 245 WithArg<0>(RecordSyncShare(&r2, 1U, &done)))); | 246 WithArg<0>(RecordSyncShare(&r2, 1U, &done)))); |
| 246 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_NOTIFICATION, types3); | 247 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_NOTIFICATION, types3); |
| 247 done.TimedWait(timeout()); | 248 done.TimedWait(timeout()); |
| 248 EXPECT_EQ(1U, r2.snapshots.size()); | 249 EXPECT_EQ(1U, r2.snapshots.size()); |
| 249 EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(types3, | 250 EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(types3, |
| 250 r2.snapshots[0]->source.types)); | 251 r2.snapshots[0]->source.types)); |
| 251 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, | 252 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, |
| 252 r2.snapshots[0]->source.updates_source); | 253 r2.snapshots[0]->source.updates_source); |
| 253 } | 254 } |
| 254 | 255 |
| 255 // Test nudge scheduling. | 256 // Test nudge scheduling. |
| 256 TEST_F(SyncerThread2Test, NudgeWithPayloads) { | 257 TEST_F(SyncerThread2Test, NudgeWithPayloads) { |
| 257 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 258 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 258 base::WaitableEvent done(false, false); | 259 base::WaitableEvent done(false, false); |
| 259 SyncShareRecords records; | 260 SyncShareRecords records; |
| 260 sessions::TypePayloadMap model_types_with_payloads; | 261 sessions::TypePayloadMap model_types_with_payloads; |
| 261 model_types_with_payloads[syncable::BOOKMARKS] = "test"; | 262 model_types_with_payloads[syncable::BOOKMARKS] = "test"; |
| 262 | 263 |
| 263 EXPECT_CALL(*syncer(), SyncShare(_)) | 264 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 264 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 265 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 265 WithArg<0>(RecordSyncShare(&records, 1U, &done)))) | 266 WithArg<0>(RecordSyncShare(&records, 1U, &done)))) |
| 266 .RetiresOnSaturation(); | 267 .RetiresOnSaturation(); |
| 267 syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_LOCAL, | 268 syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_LOCAL, |
| 268 model_types_with_payloads); | 269 model_types_with_payloads); |
| 269 done.TimedWait(timeout()); | 270 done.TimedWait(timeout()); |
| 270 | 271 |
| 271 EXPECT_EQ(1U, records.snapshots.size()); | 272 EXPECT_EQ(1U, records.snapshots.size()); |
| 272 EXPECT_EQ(model_types_with_payloads, records.snapshots[0]->source.types); | 273 EXPECT_EQ(model_types_with_payloads, records.snapshots[0]->source.types); |
| 273 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 274 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 274 records.snapshots[0]->source.updates_source); | 275 records.snapshots[0]->source.updates_source); |
| 275 | 276 |
| 276 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 277 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 277 SyncShareRecords records2; | 278 SyncShareRecords records2; |
| 278 model_types_with_payloads.erase(syncable::BOOKMARKS); | 279 model_types_with_payloads.erase(syncable::BOOKMARKS); |
| 279 model_types_with_payloads[syncable::AUTOFILL] = "test2"; | 280 model_types_with_payloads[syncable::AUTOFILL] = "test2"; |
| 280 EXPECT_CALL(*syncer(), SyncShare(_)) | 281 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 281 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 282 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 282 WithArg<0>(RecordSyncShare(&records2, 1U, &done)))); | 283 WithArg<0>(RecordSyncShare(&records2, 1U, &done)))); |
| 283 syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_LOCAL, | 284 syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_LOCAL, |
| 284 model_types_with_payloads); | 285 model_types_with_payloads); |
| 285 done.TimedWait(timeout()); | 286 done.TimedWait(timeout()); |
| 286 | 287 |
| 287 EXPECT_EQ(1U, records2.snapshots.size()); | 288 EXPECT_EQ(1U, records2.snapshots.size()); |
| 288 EXPECT_EQ(model_types_with_payloads, records2.snapshots[0]->source.types); | 289 EXPECT_EQ(model_types_with_payloads, records2.snapshots[0]->source.types); |
| 289 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 290 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 290 records2.snapshots[0]->source.updates_source); | 291 records2.snapshots[0]->source.updates_source); |
| 291 } | 292 } |
| 292 | 293 |
| 293 // Test that nudges are coalesced. | 294 // Test that nudges are coalesced. |
| 294 TEST_F(SyncerThread2Test, NudgeWithPayloadsCoalescing) { | 295 TEST_F(SyncerThread2Test, NudgeWithPayloadsCoalescing) { |
| 295 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 296 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 296 base::WaitableEvent done(false, false); | 297 base::WaitableEvent done(false, false); |
| 297 SyncShareRecords r; | 298 SyncShareRecords r; |
| 298 EXPECT_CALL(*syncer(), SyncShare(_)) | 299 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 299 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 300 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 300 WithArg<0>(RecordSyncShare(&r, 1U, &done)))); | 301 WithArg<0>(RecordSyncShare(&r, 1U, &done)))); |
| 301 sessions::TypePayloadMap types1, types2, types3; | 302 sessions::TypePayloadMap types1, types2, types3; |
| 302 types1[syncable::BOOKMARKS] = "test1"; | 303 types1[syncable::BOOKMARKS] = "test1"; |
| 303 types2[syncable::AUTOFILL] = "test2"; | 304 types2[syncable::AUTOFILL] = "test2"; |
| 304 types3[syncable::THEMES] = "test3"; | 305 types3[syncable::THEMES] = "test3"; |
| 305 TimeDelta delay = TimeDelta::FromMilliseconds(20); | 306 TimeDelta delay = TimeDelta::FromMilliseconds(20); |
| 306 TimeTicks optimal_time = TimeTicks::Now() + delay; | 307 TimeTicks optimal_time = TimeTicks::Now() + delay; |
| 307 syncer_thread()->ScheduleNudgeWithPayloads(delay, NUDGE_SOURCE_UNKNOWN, | 308 syncer_thread()->ScheduleNudgeWithPayloads(delay, NUDGE_SOURCE_UNKNOWN, |
| 308 types1); | 309 types1); |
| 309 syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_LOCAL, | 310 syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_LOCAL, |
| 310 types2); | 311 types2); |
| 311 syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_NOTIFICATION, | 312 syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_NOTIFICATION, |
| 312 types3); | 313 types3); |
| 313 done.TimedWait(timeout()); | 314 done.TimedWait(timeout()); |
| 314 | 315 |
| 315 EXPECT_EQ(1U, r.snapshots.size()); | 316 EXPECT_EQ(1U, r.snapshots.size()); |
| 316 EXPECT_GE(r.times[0], optimal_time); | 317 EXPECT_GE(r.times[0], optimal_time); |
| 317 sessions::TypePayloadMap coalesced_types; | 318 sessions::TypePayloadMap coalesced_types; |
| 318 sessions::CoalescePayloads(&coalesced_types, types1); | 319 sessions::CoalescePayloads(&coalesced_types, types1); |
| 319 sessions::CoalescePayloads(&coalesced_types, types2); | 320 sessions::CoalescePayloads(&coalesced_types, types2); |
| 320 sessions::CoalescePayloads(&coalesced_types, types3); | 321 sessions::CoalescePayloads(&coalesced_types, types3); |
| 321 EXPECT_EQ(coalesced_types, r.snapshots[0]->source.types); | 322 EXPECT_EQ(coalesced_types, r.snapshots[0]->source.types); |
| 322 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, | 323 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, |
| 323 r.snapshots[0]->source.updates_source); | 324 r.snapshots[0]->source.updates_source); |
| 324 | 325 |
| 325 SyncShareRecords r2; | 326 SyncShareRecords r2; |
| 326 EXPECT_CALL(*syncer(), SyncShare(_)) | 327 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 327 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 328 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 328 WithArg<0>(RecordSyncShare(&r2, 1U, &done)))); | 329 WithArg<0>(RecordSyncShare(&r2, 1U, &done)))); |
| 329 syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_NOTIFICATION, | 330 syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_NOTIFICATION, |
| 330 types3); | 331 types3); |
| 331 done.TimedWait(timeout()); | 332 done.TimedWait(timeout()); |
| 332 EXPECT_EQ(1U, r2.snapshots.size()); | 333 EXPECT_EQ(1U, r2.snapshots.size()); |
| 333 EXPECT_EQ(types3, r2.snapshots[0]->source.types); | 334 EXPECT_EQ(types3, r2.snapshots[0]->source.types); |
| 334 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, | 335 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, |
| 335 r2.snapshots[0]->source.updates_source); | 336 r2.snapshots[0]->source.updates_source); |
| 336 } | 337 } |
| 337 | 338 |
| 338 // Test that polling works as expected. | 339 // Test that polling works as expected. |
| 339 TEST_F(SyncerThread2Test, Polling) { | 340 TEST_F(SyncerThread2Test, Polling) { |
| 340 SyncShareRecords records; | 341 SyncShareRecords records; |
| 341 base::WaitableEvent done(false, false); | 342 base::WaitableEvent done(false, false); |
| 342 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 343 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
| 343 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll_interval); | 344 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll_interval); |
| 344 EXPECT_CALL(*syncer(), SyncShare(_)).Times(AtLeast(kMinNumSamples)) | 345 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) |
| 345 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 346 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 346 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); | 347 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); |
| 347 | 348 |
| 348 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 349 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
| 349 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 350 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 350 done.TimedWait(timeout()); | 351 done.TimedWait(timeout()); |
| 351 syncer_thread()->Stop(); | 352 syncer_thread()->Stop(); |
| 352 | 353 |
| 353 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); | 354 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); |
| 354 } | 355 } |
| 355 | 356 |
| 356 // Test that the short poll interval is used. | 357 // Test that the short poll interval is used. |
| 357 TEST_F(SyncerThread2Test, PollNotificationsDisabled) { | 358 TEST_F(SyncerThread2Test, PollNotificationsDisabled) { |
| 358 SyncShareRecords records; | 359 SyncShareRecords records; |
| 359 base::WaitableEvent done(false, false); | 360 base::WaitableEvent done(false, false); |
| 360 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 361 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
| 361 syncer_thread()->OnReceivedShortPollIntervalUpdate(poll_interval); | 362 syncer_thread()->OnReceivedShortPollIntervalUpdate(poll_interval); |
| 362 syncer_thread()->set_notifications_enabled(false); | 363 syncer_thread()->set_notifications_enabled(false); |
| 363 EXPECT_CALL(*syncer(), SyncShare(_)).Times(AtLeast(kMinNumSamples)) | 364 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) |
| 364 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 365 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 365 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); | 366 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); |
| 366 | 367 |
| 367 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 368 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
| 368 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 369 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 369 done.TimedWait(timeout()); | 370 done.TimedWait(timeout()); |
| 370 syncer_thread()->Stop(); | 371 syncer_thread()->Stop(); |
| 371 | 372 |
| 372 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); | 373 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); |
| 373 } | 374 } |
| 374 | 375 |
| 375 // Test that polling intervals are updated when needed. | 376 // Test that polling intervals are updated when needed. |
| 376 TEST_F(SyncerThread2Test, PollIntervalUpdate) { | 377 TEST_F(SyncerThread2Test, PollIntervalUpdate) { |
| 377 SyncShareRecords records; | 378 SyncShareRecords records; |
| 378 base::WaitableEvent done(false, false); | 379 base::WaitableEvent done(false, false); |
| 379 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); | 380 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); |
| 380 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); | 381 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); |
| 381 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll1); | 382 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll1); |
| 382 EXPECT_CALL(*syncer(), SyncShare(_)).Times(AtLeast(kMinNumSamples)) | 383 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) |
| 383 .WillOnce(WithArg<0>( | 384 .WillOnce(WithArg<0>( |
| 384 sessions::test_util::SimulatePollIntervalUpdate(poll2))) | 385 sessions::test_util::SimulatePollIntervalUpdate(poll2))) |
| 385 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 386 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 386 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); | 387 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); |
| 387 | 388 |
| 388 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; | 389 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; |
| 389 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 390 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 390 done.TimedWait(timeout()); | 391 done.TimedWait(timeout()); |
| 391 syncer_thread()->Stop(); | 392 syncer_thread()->Stop(); |
| 392 | 393 |
| 393 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll2); | 394 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll2); |
| 394 } | 395 } |
| 395 | 396 |
| 396 // Test that a sync session is run through to completion. | 397 // Test that a sync session is run through to completion. |
| 397 TEST_F(SyncerThread2Test, HasMoreToSync) { | 398 TEST_F(SyncerThread2Test, HasMoreToSync) { |
| 398 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 399 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 399 base::WaitableEvent done(false, false); | 400 base::WaitableEvent done(false, false); |
| 400 EXPECT_CALL(*syncer(), SyncShare(_)) | 401 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 401 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync)) | 402 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync)) |
| 402 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 403 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 403 SignalEvent(&done))); | 404 SignalEvent(&done))); |
| 404 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet()); | 405 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet()); |
| 405 done.TimedWait(timeout()); | 406 done.TimedWait(timeout()); |
| 406 // If more nudges are scheduled, they'll be waited on by TearDown, and would | 407 // If more nudges are scheduled, they'll be waited on by TearDown, and would |
| 407 // cause our expectation to break. | 408 // cause our expectation to break. |
| 408 } | 409 } |
| 409 | 410 |
| 410 // Test that no syncing occurs when throttled. | 411 // Test that no syncing occurs when throttled. |
| 411 TEST_F(SyncerThread2Test, ThrottlingDoesThrottle) { | 412 TEST_F(SyncerThread2Test, ThrottlingDoesThrottle) { |
| 412 syncable::ModelTypeBitSet types; | 413 syncable::ModelTypeBitSet types; |
| 413 types[syncable::BOOKMARKS] = true; | 414 types[syncable::BOOKMARKS] = true; |
| 414 base::WaitableEvent done(false, false); | 415 base::WaitableEvent done(false, false); |
| 415 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 416 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
| 416 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 417 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
| 417 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); | 418 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); |
| 418 EXPECT_CALL(*syncer(), SyncShare(_)) | 419 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 419 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))); | 420 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))); |
| 420 | 421 |
| 421 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 422 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 422 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types); | 423 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types); |
| 423 FlushLastTask(&done); | 424 FlushLastTask(&done); |
| 424 | 425 |
| 425 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE); | 426 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE); |
| 426 syncer_thread()->ScheduleConfig(zero(), types); | 427 syncer_thread()->ScheduleConfig(zero(), types); |
| 427 FlushLastTask(&done); | 428 FlushLastTask(&done); |
| 428 } | 429 } |
| 429 | 430 |
| 430 TEST_F(SyncerThread2Test, ThrottlingExpires) { | 431 TEST_F(SyncerThread2Test, ThrottlingExpires) { |
| 431 SyncShareRecords records; | 432 SyncShareRecords records; |
| 432 base::WaitableEvent done(false, false); | 433 base::WaitableEvent done(false, false); |
| 433 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 434 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 434 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 435 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 435 TimeDelta throttle2(TimeDelta::FromMinutes(10)); | 436 TimeDelta throttle2(TimeDelta::FromMinutes(10)); |
| 436 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); | 437 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); |
| 437 | 438 |
| 438 ::testing::InSequence seq; | 439 ::testing::InSequence seq; |
| 439 EXPECT_CALL(*syncer(), SyncShare(_)) | 440 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 440 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle1))) | 441 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle1))) |
| 441 .RetiresOnSaturation(); | 442 .RetiresOnSaturation(); |
| 442 EXPECT_CALL(*syncer(), SyncShare(_)) | 443 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 443 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 444 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 444 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); | 445 WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); |
| 445 | 446 |
| 446 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; | 447 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; |
| 447 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 448 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 448 done.TimedWait(timeout()); | 449 done.TimedWait(timeout()); |
| 449 syncer_thread()->Stop(); | 450 syncer_thread()->Stop(); |
| 450 | 451 |
| 451 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); | 452 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); |
| 452 } | 453 } |
| 453 | 454 |
| 454 // Test nudges / polls don't run in config mode and config tasks do. | 455 // Test nudges / polls don't run in config mode and config tasks do. |
| 455 TEST_F(SyncerThread2Test, ConfigurationMode) { | 456 TEST_F(SyncerThread2Test, ConfigurationMode) { |
| 456 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 457 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 457 base::WaitableEvent done(false, false); | 458 base::WaitableEvent done(false, false); |
| 458 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); | 459 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); |
| 459 EXPECT_CALL(*syncer(), SyncShare(_)).Times(0); | 460 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0); |
| 460 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE); | 461 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE); |
| 461 syncable::ModelTypeBitSet nudge_types; | 462 syncable::ModelTypeBitSet nudge_types; |
| 462 nudge_types[syncable::AUTOFILL] = true; | 463 nudge_types[syncable::AUTOFILL] = true; |
| 463 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types); | 464 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types); |
| 464 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types); | 465 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, nudge_types); |
| 465 | 466 |
| 466 syncable::ModelTypeBitSet config_types; | 467 syncable::ModelTypeBitSet config_types; |
| 467 config_types[syncable::BOOKMARKS] = true; | 468 config_types[syncable::BOOKMARKS] = true; |
| 468 // TODO(tim): This will fail once CONFIGURATION tasks are implemented. Update | 469 // TODO(tim): This will fail once CONFIGURATION tasks are implemented. Update |
| 469 // the EXPECT when that happens. | 470 // the EXPECT when that happens. |
| 470 syncer_thread()->ScheduleConfig(zero(), config_types); | 471 syncer_thread()->ScheduleConfig(zero(), config_types); |
| 471 FlushLastTask(&done); | 472 FlushLastTask(&done); |
| 472 } | 473 } |
| 473 | 474 |
| 474 // Test that exponential backoff is properly triggered. | 475 // Test that exponential backoff is properly triggered. |
| 475 TEST_F(SyncerThread2Test, BackoffTriggers) { | 476 TEST_F(SyncerThread2Test, BackoffTriggers) { |
| 476 base::WaitableEvent done(false, false); | 477 base::WaitableEvent done(false, false); |
| 477 UseMockDelayProvider(); | 478 UseMockDelayProvider(); |
| 478 | 479 |
| 479 EXPECT_CALL(*syncer(), SyncShare(_)) | 480 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 480 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) | 481 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) |
| 481 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 482 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 482 SignalEvent(&done))); | 483 SignalEvent(&done))); |
| 483 EXPECT_FALSE(GetBackoffAndResetTest(&done)); | 484 EXPECT_FALSE(GetBackoffAndResetTest(&done)); |
| 484 // Note GetBackoffAndResetTest clears mocks and re-instantiates the syncer. | 485 // Note GetBackoffAndResetTest clears mocks and re-instantiates the syncer. |
| 485 EXPECT_CALL(*syncer(), SyncShare(_)) | 486 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 486 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) | 487 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) |
| 487 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 488 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 488 SignalEvent(&done))); | 489 SignalEvent(&done))); |
| 489 EXPECT_FALSE(GetBackoffAndResetTest(&done)); | 490 EXPECT_FALSE(GetBackoffAndResetTest(&done)); |
| 490 EXPECT_CALL(*syncer(), SyncShare(_)) | 491 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 491 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) | 492 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) |
| 492 .WillRepeatedly(DoAll(Invoke( | 493 .WillRepeatedly(DoAll(Invoke( |
| 493 sessions::test_util::SimulateDownloadUpdatesFailed), | 494 sessions::test_util::SimulateDownloadUpdatesFailed), |
| 494 SignalEvent(&done))); | 495 SignalEvent(&done))); |
| 495 EXPECT_TRUE(GetBackoffAndResetTest(&done)); | 496 EXPECT_TRUE(GetBackoffAndResetTest(&done)); |
| 496 EXPECT_CALL(*syncer(), SyncShare(_)) | 497 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 497 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) | 498 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) |
| 498 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 499 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 499 SignalEvent(&done))); | 500 SignalEvent(&done))); |
| 500 EXPECT_TRUE(GetBackoffAndResetTest(&done)); | 501 EXPECT_TRUE(GetBackoffAndResetTest(&done)); |
| 501 EXPECT_CALL(*syncer(), SyncShare(_)) | 502 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 502 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) | 503 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) |
| 503 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) | 504 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) |
| 504 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 505 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 505 SignalEvent(&done))); | 506 SignalEvent(&done))); |
| 506 EXPECT_FALSE(GetBackoffAndResetTest(&done)); | 507 EXPECT_FALSE(GetBackoffAndResetTest(&done)); |
| 507 EXPECT_CALL(*syncer(), SyncShare(_)) | 508 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 508 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) | 509 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) |
| 509 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) | 510 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) |
| 510 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 511 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 511 SignalEvent(&done))); | 512 SignalEvent(&done))); |
| 512 EXPECT_FALSE(GetBackoffAndResetTest(&done)); | 513 EXPECT_FALSE(GetBackoffAndResetTest(&done)); |
| 513 } | 514 } |
| 514 | 515 |
| 515 // Test that no polls or extraneous nudges occur when in backoff. | 516 // Test that no polls or extraneous nudges occur when in backoff. |
| 516 TEST_F(SyncerThread2Test, BackoffDropsJobs) { | 517 TEST_F(SyncerThread2Test, BackoffDropsJobs) { |
| 517 SyncShareRecords r; | 518 SyncShareRecords r; |
| 518 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 519 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
| 519 base::WaitableEvent done(false, false); | 520 base::WaitableEvent done(false, false); |
| 520 syncable::ModelTypeBitSet types; | 521 syncable::ModelTypeBitSet types; |
| 521 types[syncable::BOOKMARKS] = true; | 522 types[syncable::BOOKMARKS] = true; |
| 522 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); | 523 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); |
| 523 UseMockDelayProvider(); | 524 UseMockDelayProvider(); |
| 524 | 525 |
| 525 EXPECT_CALL(*syncer(), SyncShare(_)).Times(2) | 526 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(2) |
| 526 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 527 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 527 RecordSyncShareAndPostSignal(&r, 2U, this, &done))); | 528 RecordSyncShareAndPostSignal(&r, 2U, this, &done))); |
| 528 EXPECT_CALL(*delay(), GetDelay(_)) | 529 EXPECT_CALL(*delay(), GetDelay(_)) |
| 529 .WillRepeatedly(Return(TimeDelta::FromDays(1))); | 530 .WillRepeatedly(Return(TimeDelta::FromDays(1))); |
| 530 | 531 |
| 531 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 532 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 532 ASSERT_TRUE(done.TimedWait(timeout())); | 533 ASSERT_TRUE(done.TimedWait(timeout())); |
| 533 done.Reset(); | 534 done.Reset(); |
| 534 | 535 |
| 535 Mock::VerifyAndClearExpectations(syncer()); | 536 Mock::VerifyAndClearExpectations(syncer()); |
| 536 EXPECT_EQ(2U, r.snapshots.size()); | 537 EXPECT_EQ(2U, r.snapshots.size()); |
| 537 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, | 538 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, |
| 538 r.snapshots[0]->source.updates_source); | 539 r.snapshots[0]->source.updates_source); |
| 539 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | 540 EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, |
| 540 r.snapshots[1]->source.updates_source); | 541 r.snapshots[1]->source.updates_source); |
| 541 | 542 |
| 542 EXPECT_CALL(*syncer(), SyncShare(_)).Times(1) | 543 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) |
| 543 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 544 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 544 RecordSyncShareAndPostSignal(&r, 1U, this, &done))); | 545 RecordSyncShareAndPostSignal(&r, 1U, this, &done))); |
| 545 | 546 |
| 546 // We schedule a nudge with enough delay (10X poll interval) that at least | 547 // We schedule a nudge with enough delay (10X poll interval) that at least |
| 547 // one or two polls would have taken place. The nudge should succeed. | 548 // one or two polls would have taken place. The nudge should succeed. |
| 548 syncer_thread()->ScheduleNudge(poll * 10, NUDGE_SOURCE_LOCAL, types); | 549 syncer_thread()->ScheduleNudge(poll * 10, NUDGE_SOURCE_LOCAL, types); |
| 549 ASSERT_TRUE(done.TimedWait(timeout())); | 550 ASSERT_TRUE(done.TimedWait(timeout())); |
| 550 done.Reset(); | 551 done.Reset(); |
| 551 | 552 |
| 552 Mock::VerifyAndClearExpectations(syncer()); | 553 Mock::VerifyAndClearExpectations(syncer()); |
| 553 Mock::VerifyAndClearExpectations(delay()); | 554 Mock::VerifyAndClearExpectations(delay()); |
| 554 EXPECT_EQ(3U, r.snapshots.size()); | 555 EXPECT_EQ(3U, r.snapshots.size()); |
| 555 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 556 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 556 r.snapshots[2]->source.updates_source); | 557 r.snapshots[2]->source.updates_source); |
| 557 | 558 |
| 558 EXPECT_CALL(*syncer(), SyncShare(_)).Times(0); | 559 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0); |
| 559 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 560 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
| 560 | 561 |
| 561 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE); | 562 syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE); |
| 562 syncer_thread()->ScheduleConfig(zero(), types); | 563 syncer_thread()->ScheduleConfig(zero(), types); |
| 563 FlushLastTask(&done); | 564 FlushLastTask(&done); |
| 564 | 565 |
| 565 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 566 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 566 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types); | 567 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types); |
| 567 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types); | 568 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types); |
| 568 FlushLastTask(&done); | 569 FlushLastTask(&done); |
| 569 } | 570 } |
| 570 | 571 |
| 571 // Test that backoff is shaping traffic properly with consecutive errors. | 572 // Test that backoff is shaping traffic properly with consecutive errors. |
| 572 TEST_F(SyncerThread2Test, BackoffElevation) { | 573 TEST_F(SyncerThread2Test, BackoffElevation) { |
| 573 SyncShareRecords r; | 574 SyncShareRecords r; |
| 574 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 575 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
| 575 base::WaitableEvent done(false, false); | 576 base::WaitableEvent done(false, false); |
| 576 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); | 577 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); |
| 577 UseMockDelayProvider(); | 578 UseMockDelayProvider(); |
| 578 | 579 |
| 579 const TimeDelta first = TimeDelta::FromSeconds(1); | 580 const TimeDelta first = TimeDelta::FromSeconds(1); |
| 580 const TimeDelta second = TimeDelta::FromMilliseconds(10); | 581 const TimeDelta second = TimeDelta::FromMilliseconds(10); |
| 581 const TimeDelta third = TimeDelta::FromMilliseconds(20); | 582 const TimeDelta third = TimeDelta::FromMilliseconds(20); |
| 582 const TimeDelta fourth = TimeDelta::FromMilliseconds(30); | 583 const TimeDelta fourth = TimeDelta::FromMilliseconds(30); |
| 583 const TimeDelta fifth = TimeDelta::FromDays(1); | 584 const TimeDelta fifth = TimeDelta::FromDays(1); |
| 584 | 585 |
| 585 EXPECT_CALL(*syncer(), SyncShare(_)).Times(kMinNumSamples) | 586 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(kMinNumSamples) |
| 586 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 587 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 587 RecordSyncShareAndPostSignal(&r, kMinNumSamples, this, &done))); | 588 RecordSyncShareAndPostSignal(&r, kMinNumSamples, this, &done))); |
| 588 | 589 |
| 589 EXPECT_CALL(*delay(), GetDelay(Eq(first))).WillOnce(Return(second)) | 590 EXPECT_CALL(*delay(), GetDelay(Eq(first))).WillOnce(Return(second)) |
| 590 .RetiresOnSaturation(); | 591 .RetiresOnSaturation(); |
| 591 EXPECT_CALL(*delay(), GetDelay(Eq(second))).WillOnce(Return(third)) | 592 EXPECT_CALL(*delay(), GetDelay(Eq(second))).WillOnce(Return(third)) |
| 592 .RetiresOnSaturation(); | 593 .RetiresOnSaturation(); |
| 593 EXPECT_CALL(*delay(), GetDelay(Eq(third))).WillOnce(Return(fourth)) | 594 EXPECT_CALL(*delay(), GetDelay(Eq(third))).WillOnce(Return(fourth)) |
| 594 .RetiresOnSaturation(); | 595 .RetiresOnSaturation(); |
| 595 EXPECT_CALL(*delay(), GetDelay(Eq(fourth))).WillOnce(Return(fifth)); | 596 EXPECT_CALL(*delay(), GetDelay(Eq(fourth))).WillOnce(Return(fifth)); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 606 // following a succession of failures. | 607 // following a succession of failures. |
| 607 TEST_F(SyncerThread2Test, BackoffRelief) { | 608 TEST_F(SyncerThread2Test, BackoffRelief) { |
| 608 SyncShareRecords r; | 609 SyncShareRecords r; |
| 609 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 610 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
| 610 base::WaitableEvent done(false, false); | 611 base::WaitableEvent done(false, false); |
| 611 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); | 612 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); |
| 612 UseMockDelayProvider(); | 613 UseMockDelayProvider(); |
| 613 | 614 |
| 614 const TimeDelta backoff = TimeDelta::FromMilliseconds(100); | 615 const TimeDelta backoff = TimeDelta::FromMilliseconds(100); |
| 615 | 616 |
| 616 EXPECT_CALL(*syncer(), SyncShare(_)) | 617 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 617 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) | 618 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) |
| 618 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) | 619 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) |
| 619 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 620 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 620 RecordSyncShareAndPostSignal(&r, kMinNumSamples, this, &done))); | 621 RecordSyncShareAndPostSignal(&r, kMinNumSamples, this, &done))); |
| 621 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); | 622 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); |
| 622 | 623 |
| 623 // Optimal start for the post-backoff poll party. | 624 // Optimal start for the post-backoff poll party. |
| 624 TimeTicks optimal_start = TimeTicks::Now() + poll + backoff; | 625 TimeTicks optimal_start = TimeTicks::Now() + poll + backoff; |
| 625 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | 626 syncer_thread()->Start(SyncerThread::NORMAL_MODE); |
| 626 done.TimedWait(timeout()); | 627 done.TimedWait(timeout()); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 648 EXPECT_LE(TimeDelta::FromSeconds(10), | 649 EXPECT_LE(TimeDelta::FromSeconds(10), |
| 649 SyncerThread::GetRecommendedDelay(TimeDelta::FromSeconds(10))); | 650 SyncerThread::GetRecommendedDelay(TimeDelta::FromSeconds(10))); |
| 650 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds), | 651 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds), |
| 651 SyncerThread::GetRecommendedDelay( | 652 SyncerThread::GetRecommendedDelay( |
| 652 TimeDelta::FromSeconds(kMaxBackoffSeconds))); | 653 TimeDelta::FromSeconds(kMaxBackoffSeconds))); |
| 653 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds), | 654 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds), |
| 654 SyncerThread::GetRecommendedDelay( | 655 SyncerThread::GetRecommendedDelay( |
| 655 TimeDelta::FromSeconds(kMaxBackoffSeconds + 1))); | 656 TimeDelta::FromSeconds(kMaxBackoffSeconds + 1))); |
| 656 } | 657 } |
| 657 | 658 |
| 659 // Test that appropriate syncer steps are requested for each job type. | |
| 660 TEST_F(SyncerThread2Test, SyncerSteps) { | |
| 661 // Nudges. | |
| 662 base::WaitableEvent done(false, false); | |
| 663 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) | |
| 664 .Times(1); | |
| 665 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | |
| 666 syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet()); | |
| 667 FlushLastTask(&done); | |
| 668 syncer_thread()->Stop(); | |
| 669 Mock::VerifyAndClearExpectations(syncer()); | |
| 670 | |
| 671 // ClearUserData. | |
| 672 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, SYNCER_END)) | |
| 673 .Times(1); | |
| 674 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | |
| 675 syncer_thread()->ScheduleClearUserData(); | |
| 676 FlushLastTask(&done); | |
| 677 syncer_thread()->Stop(); | |
| 678 Mock::VerifyAndClearExpectations(syncer()); | |
| 679 | |
| 680 // Poll. | |
| 681 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) | |
| 682 .Times(AtLeast(1)) | |
| 683 .WillRepeatedly(SignalEvent(&done)); | |
| 684 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | |
| 685 syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); | |
| 686 syncer_thread()->Start(SyncerThread::NORMAL_MODE); | |
| 687 done.TimedWait(timeout()); | |
| 688 syncer_thread()->Stop(); | |
| 689 Mock::VerifyAndClearExpectations(syncer()); | |
| 690 done.Reset(); | |
|
Nicolas Zea
2011/02/03 00:39:07
Test configuration as well?
tim (not reviewing)
2011/02/03 00:56:15
Well... I didn't actually implement configuration
| |
| 691 } | |
| 692 | |
| 658 // Test config tasks don't run during normal mode. | 693 // Test config tasks don't run during normal mode. |
| 659 // TODO(tim): Implement this test and then the functionality! | 694 // TODO(tim): Implement this test and then the functionality! |
| 660 TEST_F(SyncerThread2Test, DISABLED_NoConfigDuringNormal) { | 695 TEST_F(SyncerThread2Test, DISABLED_NoConfigDuringNormal) { |
| 661 } | 696 } |
| 662 | 697 |
| 663 // Test that starting the syncer thread without a valid connection doesn't | 698 // Test that starting the syncer thread without a valid connection doesn't |
| 664 // break things when a connection is detected. | 699 // break things when a connection is detected. |
| 665 // Test config tasks don't run during normal mode. | 700 // Test config tasks don't run during normal mode. |
| 666 // TODO(tim): Implement this test and then the functionality! | 701 // TODO(tim): Implement this test and then the functionality! |
| 667 TEST_F(SyncerThread2Test, DISABLED_StartWhenNotConnected) { | 702 TEST_F(SyncerThread2Test, DISABLED_StartWhenNotConnected) { |
| 668 | 703 |
| 669 } | 704 } |
| 670 | 705 |
| 671 } // namespace s3 | 706 } // namespace s3 |
| 672 } // namespace browser_sync | 707 } // namespace browser_sync |
| 673 | 708 |
| 674 // SyncerThread won't outlive the test! | 709 // SyncerThread won't outlive the test! |
| 675 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::s3::SyncerThread2Test); | 710 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::s3::SyncerThread2Test); |
| 676 | 711 |
| OLD | NEW |