| OLD | NEW |
| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 | 66 |
| 67 void PumpLoop() { | 67 void PumpLoop() { |
| 68 // Do it this way instead of RunAllPending to pump loop exactly once | 68 // Do it this way instead of RunAllPending to pump loop exactly once |
| 69 // (necessary in the presence of timers; see comment in | 69 // (necessary in the presence of timers; see comment in |
| 70 // QuitLoopNow). | 70 // QuitLoopNow). |
| 71 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&QuitLoopNow)); | 71 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&QuitLoopNow)); |
| 72 RunLoop(); | 72 RunLoop(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void PumpLoopFor(base::TimeDelta time) { |
| 76 // Allow the loop to run for the specified amount of time. |
| 77 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 78 base::Bind(&QuitLoopNow), |
| 79 time); |
| 80 RunLoop(); |
| 81 } |
| 82 |
| 75 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) { | 83 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) { |
| 76 ModelSafeRoutingInfo routes; | 84 ModelSafeRoutingInfo routes; |
| 77 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { | 85 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { |
| 78 routes[iter.Get()] = GROUP_PASSIVE; | 86 routes[iter.Get()] = GROUP_PASSIVE; |
| 79 } | 87 } |
| 80 return routes; | 88 return routes; |
| 81 } | 89 } |
| 82 | 90 |
| 83 // Convenient to use in tests wishing to analyze SyncShare calls over time. | 91 // Convenient to use in tests wishing to analyze SyncShare calls over time. |
| 84 static const size_t kMinNumSamples = 5; | 92 static const size_t kMinNumSamples = 5; |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 // This nudge should fail and put us into backoff. Thanks to our mock | 976 // This nudge should fail and put us into backoff. Thanks to our mock |
| 969 // GetDelay() setup above, this will be a long backoff. | 977 // GetDelay() setup above, this will be a long backoff. |
| 970 scheduler()->ScheduleNudgeAsync(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 978 scheduler()->ScheduleNudgeAsync(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
| 971 RunLoop(); | 979 RunLoop(); |
| 972 | 980 |
| 973 Mock::VerifyAndClearExpectations(syncer()); | 981 Mock::VerifyAndClearExpectations(syncer()); |
| 974 ASSERT_EQ(1U, r.snapshots.size()); | 982 ASSERT_EQ(1U, r.snapshots.size()); |
| 975 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 983 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 976 r.snapshots[0].source().updates_source); | 984 r.snapshots[0].source().updates_source); |
| 977 | 985 |
| 978 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) | 986 // Wait a while (10x poll interval) so a few poll jobs will be attempted. |
| 979 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 987 PumpLoopFor(poll * 10); |
| 980 RecordSyncShare(&r))); | |
| 981 | 988 |
| 982 // We schedule a nudge with enough delay (10X poll interval) that at least | 989 // Try (and fail) to schedule a nudge. |
| 983 // one or two polls would have taken place. The nudge should succeed. | |
| 984 scheduler()->ScheduleNudgeAsync( | 990 scheduler()->ScheduleNudgeAsync( |
| 985 poll * 10, NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 991 base::TimeDelta::FromMilliseconds(1), |
| 986 RunLoop(); | 992 NUDGE_SOURCE_LOCAL, |
| 993 types, |
| 994 FROM_HERE); |
| 987 | 995 |
| 988 Mock::VerifyAndClearExpectations(syncer()); | 996 Mock::VerifyAndClearExpectations(syncer()); |
| 989 Mock::VerifyAndClearExpectations(delay()); | 997 Mock::VerifyAndClearExpectations(delay()); |
| 990 ASSERT_EQ(2U, r.snapshots.size()); | 998 |
| 991 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 999 ASSERT_EQ(1U, r.snapshots.size()); |
| 992 r.snapshots[1].source().updates_source); | |
| 993 | 1000 |
| 994 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 1001 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
| 995 | 1002 |
| 996 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1003 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 997 | 1004 |
| 998 CallbackCounter counter; | 1005 CallbackCounter counter; |
| 999 ConfigurationParams params( | 1006 ConfigurationParams params( |
| 1000 GetUpdatesCallerInfo::RECONFIGURATION, | 1007 GetUpdatesCallerInfo::RECONFIGURATION, |
| 1001 types, | 1008 types, |
| 1002 TypesToRoutingInfo(types), | 1009 TypesToRoutingInfo(types), |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 1288 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 1282 scheduler()->ScheduleConfiguration(params); | 1289 scheduler()->ScheduleConfiguration(params); |
| 1283 | 1290 |
| 1284 scheduler()->OnConnectionStatusChange(); | 1291 scheduler()->OnConnectionStatusChange(); |
| 1285 scheduler()->OnConnectionStatusChange(); | 1292 scheduler()->OnConnectionStatusChange(); |
| 1286 | 1293 |
| 1287 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1294 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
| 1288 } | 1295 } |
| 1289 | 1296 |
| 1290 } // namespace syncer | 1297 } // namespace syncer |
| OLD | NEW |