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

Unified Diff: sync/engine/sync_scheduler_unittest.cc

Issue 10917234: sync: make scheduling logic and job ownership more obvious. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: sync/engine/sync_scheduler_unittest.cc
diff --git a/sync/engine/sync_scheduler_unittest.cc b/sync/engine/sync_scheduler_unittest.cc
index 1bb52453508f13eb28e688209c7b78911d7803ff..ce7a0254fd40bf57823b533badcc36c9edcdcf39 100644
--- a/sync/engine/sync_scheduler_unittest.cc
+++ b/sync/engine/sync_scheduler_unittest.cc
@@ -42,7 +42,7 @@ using sync_pb::GetUpdatesCallerInfo;
class MockSyncer : public Syncer {
public:
- MOCK_METHOD3(SyncShare, void(sessions::SyncSession*, SyncerStep,
+ MOCK_METHOD3(SyncShare, bool(sessions::SyncSession*, SyncerStep,
SyncerStep));
};
@@ -101,6 +101,7 @@ class SyncSchedulerTest : public testing::Test {
};
virtual void SetUp() {
+ message_loop_.reset(new MessageLoop());
dir_maker_.SetUp();
syncer_ = new MockSyncer();
delay_ = NULL;
@@ -110,6 +111,7 @@ class SyncSchedulerTest : public testing::Test {
routing_info_[THEMES] = GROUP_UI;
routing_info_[NIGORI] = GROUP_PASSIVE;
+ workers_.clear();
workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI)));
workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB)));
workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE)));
@@ -223,7 +225,7 @@ class SyncSchedulerTest : public testing::Test {
}
base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_;
- MessageLoop message_loop_;
+ scoped_ptr<MessageLoop> message_loop_;
akalin 2012/10/26 06:52:29 why'd you have to do this?
tim (not reviewing) 2012/10/26 22:52:27 Ah, leftover from some debugging. Undone.
TestDirectorySetterUpper dir_maker_;
scoped_ptr<MockConnectionManager> connection_;
scoped_ptr<SyncSessionContext> context_;
@@ -245,6 +247,7 @@ ACTION_P(RecordSyncShare, record) {
RecordSyncShareImpl(arg0, record);
if (MessageLoop::current()->is_running())
QuitLoopNow();
+ return true;
}
ACTION_P2(RecordSyncShareMultiple, record, quit_after) {
@@ -254,15 +257,18 @@ ACTION_P2(RecordSyncShareMultiple, record, quit_after) {
MessageLoop::current()->is_running()) {
QuitLoopNow();
}
+ return true;
}
ACTION(AddFailureAndQuitLoopNow) {
ADD_FAILURE();
QuitLoopNow();
+ return true;
}
ACTION(QuitLoopNowAction) {
QuitLoopNow();
+ return true;
}
// Test nudge scheduling.
@@ -646,8 +652,10 @@ TEST_F(SyncSchedulerTest, PollIntervalUpdate) {
TimeDelta poll2(TimeDelta::FromMilliseconds(30));
scheduler()->OnReceivedLongPollIntervalUpdate(poll1);
EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples))
- .WillOnce(WithArg<0>(
- sessions::test_util::SimulatePollIntervalUpdate(poll2)))
+ .WillOnce(DoAll(
+ WithArg<0>(
+ sessions::test_util::SimulatePollIntervalUpdate(poll2)),
+ Return(true)))
.WillRepeatedly(
DoAll(Invoke(sessions::test_util::SimulateSuccess),
WithArg<0>(
@@ -695,7 +703,8 @@ TEST_F(SyncSchedulerTest, SessionsCommitDelay) {
// Test that a sync session is run through to completion.
TEST_F(SyncSchedulerTest, HasMoreToSync) {
EXPECT_CALL(*syncer(), SyncShare(_,_,_))
- .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync))
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateHasMoreToSync),
+ Return(true)))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
QuitLoopNowAction()));
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
@@ -710,7 +719,8 @@ TEST_F(SyncSchedulerTest, HasMoreToSync) {
// Test that continuations can go into backoff.
TEST_F(SyncSchedulerTest, HasMoreToSyncThenFails) {
EXPECT_CALL(*syncer(), SyncShare(_,_,_))
- .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync))
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateHasMoreToSync),
+ Return(true)))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
QuitLoopNowAction()));
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
@@ -730,7 +740,9 @@ TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) {
scheduler()->OnReceivedLongPollIntervalUpdate(poll);
EXPECT_CALL(*syncer(), SyncShare(_,_,_))
- .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle)))
+ .WillOnce(DoAll(
+ WithArg<0>(sessions::test_util::SimulateThrottled(throttle)),
+ Return(true)))
.WillRepeatedly(AddFailureAndQuitLoopNow());
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
@@ -759,7 +771,9 @@ TEST_F(SyncSchedulerTest, ThrottlingExpires) {
::testing::InSequence seq;
EXPECT_CALL(*syncer(), SyncShare(_,_,_))
- .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)))
+ .WillOnce(DoAll(
+ WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)),
+ Return(true)))
.RetiresOnSaturation();
EXPECT_CALL(*syncer(), SyncShare(_,_,_))
.WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
@@ -857,7 +871,9 @@ TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnce) {
// retry. Expect that this clears the backoff state.
TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) {
EXPECT_CALL(*syncer(), SyncShare(_,_,_))
- .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed))
+ .WillOnce(DoAll(
+ Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
+ Return(true)))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
QuitLoopNowAction()));
EXPECT_FALSE(RunAndGetBackoff());
@@ -867,7 +883,9 @@ TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) {
// that this clears the backoff state.
TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) {
EXPECT_CALL(*syncer(), SyncShare(_,_,_))
- .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed))
+ .WillOnce(DoAll(
+ Invoke(sessions::test_util::SimulateCommitFailed),
+ Return(true)))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
QuitLoopNowAction()));
EXPECT_FALSE(RunAndGetBackoff());
@@ -877,7 +895,9 @@ TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) {
// Expect this will leave the scheduler in backoff.
TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) {
EXPECT_CALL(*syncer(), SyncShare(_,_,_))
- .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed))
+ .WillOnce(DoAll(
+ Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
+ Return(true)))
.WillRepeatedly(DoAll(
Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
QuitLoopNowAction()));
@@ -888,7 +908,9 @@ TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) {
// updates. Expect this will leave the scheduler in backoff.
TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) {
EXPECT_CALL(*syncer(), SyncShare(_,_,_))
- .WillOnce(Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed))
+ .WillOnce(DoAll(
+ Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed),
+ Return(true)))
.WillRepeatedly(DoAll(
Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed),
QuitLoopNowAction()));
@@ -1070,7 +1092,8 @@ TEST_F(SyncSchedulerTest, TransientPollFailure) {
TEST_F(SyncSchedulerTest, SyncerSteps) {
// Nudges.
EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END))
- .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
+ Return(true)));
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
scheduler()->ScheduleNudgeAsync(
@@ -1084,7 +1107,8 @@ TEST_F(SyncSchedulerTest, SyncerSteps) {
// Configuration.
EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES))
- .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
+ Return(true)));
StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
ModelTypeSet model_types(BOOKMARKS);
@@ -1125,8 +1149,10 @@ TEST_F(SyncSchedulerTest, StartWhenNotConnected) {
connection()->SetServerNotReachable();
connection()->UpdateConnectionStatus();
EXPECT_CALL(*syncer(), SyncShare(_,_,_))
- .WillOnce(Invoke(sessions::test_util::SimulateConnectionFailure))
- .WillOnce(QuitLoopNowAction());
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure),
+ Return(true)))
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
+ QuitLoopNowAction()));
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
scheduler()->ScheduleNudgeAsync(

Powered by Google App Engine
This is Rietveld 408576698