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/message_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
11 #include "sync/engine/backoff_delay_provider.h" | 11 #include "sync/engine/backoff_delay_provider.h" |
12 #include "sync/engine/sync_scheduler_impl.h" | 12 #include "sync/engine/sync_scheduler_impl.h" |
13 #include "sync/engine/syncer.h" | 13 #include "sync/engine/syncer.h" |
14 #include "sync/internal_api/public/base/cancelation_signal.h" | 14 #include "sync/internal_api/public/base/cancelation_signal.h" |
15 #include "sync/internal_api/public/base/model_type_test_util.h" | 15 #include "sync/internal_api/public/base/model_type_test_util.h" |
16 #include "sync/sessions/test_util.h" | 16 #include "sync/sessions/test_util.h" |
17 #include "sync/test/callback_counter.h" | 17 #include "sync/test/callback_counter.h" |
18 #include "sync/test/engine/fake_model_worker.h" | 18 #include "sync/test/engine/fake_model_worker.h" |
19 #include "sync/test/engine/mock_connection_manager.h" | 19 #include "sync/test/engine/mock_connection_manager.h" |
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 connection()->UpdateConnectionStatus(); | 1157 connection()->UpdateConnectionStatus(); |
1158 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1158 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1159 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), | 1159 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), |
1160 Return(true))) | 1160 Return(true))) |
1161 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1161 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1162 Return(true))); | 1162 Return(true))); |
1163 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1163 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1164 | 1164 |
1165 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1165 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
1166 // Should save the nudge for until after the server is reachable. | 1166 // Should save the nudge for until after the server is reachable. |
1167 base::MessageLoop::current()->RunUntilIdle(); | 1167 base::RunLoop().RunUntilIdle(); |
1168 | 1168 |
1169 scheduler()->OnConnectionStatusChange(); | 1169 scheduler()->OnConnectionStatusChange(); |
1170 connection()->SetServerReachable(); | 1170 connection()->SetServerReachable(); |
1171 connection()->UpdateConnectionStatus(); | 1171 connection()->UpdateConnectionStatus(); |
1172 base::MessageLoop::current()->RunUntilIdle(); | 1172 base::RunLoop().RunUntilIdle(); |
1173 } | 1173 } |
1174 | 1174 |
1175 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) { | 1175 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) { |
1176 UseMockDelayProvider(); | 1176 UseMockDelayProvider(); |
1177 EXPECT_CALL(*delay(), GetDelay(_)) | 1177 EXPECT_CALL(*delay(), GetDelay(_)) |
1178 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); | 1178 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); |
1179 | 1179 |
1180 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1180 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1181 connection()->SetServerNotReachable(); | 1181 connection()->SetServerNotReachable(); |
1182 connection()->UpdateConnectionStatus(); | 1182 connection()->UpdateConnectionStatus(); |
1183 | 1183 |
1184 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1184 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1185 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), | 1185 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), |
1186 Return(true))) | 1186 Return(true))) |
1187 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1187 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1188 Return(true))); | 1188 Return(true))); |
1189 | 1189 |
1190 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1190 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
1191 PumpLoop(); // To get PerformDelayedNudge called. | 1191 PumpLoop(); // To get PerformDelayedNudge called. |
1192 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1192 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
1193 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1193 ASSERT_TRUE(scheduler()->IsBackingOff()); |
1194 | 1194 |
1195 // Before we run the scheduled canary, trigger a server connection change. | 1195 // Before we run the scheduled canary, trigger a server connection change. |
1196 scheduler()->OnConnectionStatusChange(); | 1196 scheduler()->OnConnectionStatusChange(); |
1197 connection()->SetServerReachable(); | 1197 connection()->SetServerReachable(); |
1198 connection()->UpdateConnectionStatus(); | 1198 connection()->UpdateConnectionStatus(); |
1199 base::MessageLoop::current()->RunUntilIdle(); | 1199 base::RunLoop().RunUntilIdle(); |
1200 } | 1200 } |
1201 | 1201 |
1202 // This was supposed to test the scenario where we receive a nudge while a | 1202 // This was supposed to test the scenario where we receive a nudge while a |
1203 // connection change canary is scheduled, but has not run yet. Since we've made | 1203 // connection change canary is scheduled, but has not run yet. Since we've made |
1204 // the connection change canary synchronous, this is no longer possible. | 1204 // the connection change canary synchronous, this is no longer possible. |
1205 TEST_F(SyncSchedulerTest, ConnectionChangeCanaryPreemptedByNudge) { | 1205 TEST_F(SyncSchedulerTest, ConnectionChangeCanaryPreemptedByNudge) { |
1206 UseMockDelayProvider(); | 1206 UseMockDelayProvider(); |
1207 EXPECT_CALL(*delay(), GetDelay(_)) | 1207 EXPECT_CALL(*delay(), GetDelay(_)) |
1208 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); | 1208 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); |
1209 | 1209 |
(...skipping 14 matching lines...) Expand all Loading... |
1224 PumpLoop(); // To get PerformDelayedNudge called. | 1224 PumpLoop(); // To get PerformDelayedNudge called. |
1225 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1225 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
1226 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1226 ASSERT_TRUE(scheduler()->IsBackingOff()); |
1227 | 1227 |
1228 // Before we run the scheduled canary, trigger a server connection change. | 1228 // Before we run the scheduled canary, trigger a server connection change. |
1229 scheduler()->OnConnectionStatusChange(); | 1229 scheduler()->OnConnectionStatusChange(); |
1230 PumpLoop(); | 1230 PumpLoop(); |
1231 connection()->SetServerReachable(); | 1231 connection()->SetServerReachable(); |
1232 connection()->UpdateConnectionStatus(); | 1232 connection()->UpdateConnectionStatus(); |
1233 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1233 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
1234 base::MessageLoop::current()->RunUntilIdle(); | 1234 base::RunLoop().RunUntilIdle(); |
1235 } | 1235 } |
1236 | 1236 |
1237 // Tests that we don't crash trying to run two canaries at once if we receive | 1237 // Tests that we don't crash trying to run two canaries at once if we receive |
1238 // extra connection status change notifications. See crbug.com/190085. | 1238 // extra connection status change notifications. See crbug.com/190085. |
1239 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { | 1239 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { |
1240 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 1240 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
1241 .WillRepeatedly(DoAll( | 1241 .WillRepeatedly(DoAll( |
1242 Invoke(sessions::test_util::SimulateConfigureConnectionFailure), | 1242 Invoke(sessions::test_util::SimulateConfigureConnectionFailure), |
1243 Return(true))); | 1243 Return(true))); |
1244 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1244 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1369 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1370 RecordSyncShare(×))); | 1370 RecordSyncShare(×))); |
1371 | 1371 |
1372 // Run to wait for retrying. | 1372 // Run to wait for retrying. |
1373 RunLoop(); | 1373 RunLoop(); |
1374 | 1374 |
1375 StopSyncScheduler(); | 1375 StopSyncScheduler(); |
1376 } | 1376 } |
1377 | 1377 |
1378 } // namespace syncer | 1378 } // namespace syncer |
OLD | NEW |