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

Unified Diff: sync/engine/sync_scheduler_unittest.cc

Issue 19982002: sync: Remove SyncSourceInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove "sources" from SyncScheduler unit tests Created 7 years, 5 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
« no previous file with comments | « sync/engine/sync_scheduler_impl.cc ('k') | sync/engine/syncer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/engine/sync_scheduler_unittest.cc
diff --git a/sync/engine/sync_scheduler_unittest.cc b/sync/engine/sync_scheduler_unittest.cc
index 3fb2042fe05b57a50ed09bed6c7eae5fcf8128de..3f6731bd9a21523cea832769da1d47f6c04b921e 100644
--- a/sync/engine/sync_scheduler_unittest.cc
+++ b/sync/engine/sync_scheduler_unittest.cc
@@ -11,7 +11,6 @@
#include "sync/engine/backoff_delay_provider.h"
#include "sync/engine/sync_scheduler_impl.h"
#include "sync/engine/syncer.h"
-#include "sync/internal_api/public/base/model_type_invalidation_map_test_util.h"
#include "sync/sessions/test_util.h"
#include "sync/test/callback_counter.h"
#include "sync/test/engine/fake_model_worker.h"
@@ -26,10 +25,8 @@ using base::TimeTicks;
using testing::_;
using testing::AtLeast;
using testing::DoAll;
-using testing::Eq;
using testing::Invoke;
using testing::Mock;
-using testing::Not;
using testing::Return;
using testing::WithArg;
using testing::WithArgs;
@@ -37,7 +34,6 @@ using testing::WithArgs;
namespace syncer {
using sessions::SyncSession;
using sessions::SyncSessionContext;
-using sessions::SyncSessionSnapshot;
using sync_pb::GetUpdatesCallerInfo;
class MockSyncer : public Syncer {
@@ -45,14 +41,15 @@ class MockSyncer : public Syncer {
MOCK_METHOD3(NormalSyncShare, bool(ModelTypeSet,
const sessions::NudgeTracker&,
sessions::SyncSession*));
- MOCK_METHOD2(ConfigureSyncShare, bool(ModelTypeSet, sessions::SyncSession*));
+ MOCK_METHOD3(ConfigureSyncShare,
+ bool(ModelTypeSet,
+ sync_pb::GetUpdatesCallerInfo::GetUpdatesSource,
+ SyncSession*));
MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, sessions::SyncSession*));
};
-// Used when tests want to record syncing activity to examine later.
struct SyncShareRecords {
std::vector<TimeTicks> times;
tim (not reviewing) 2013/08/02 22:49:39 This could just be made a typedef.
- std::vector<SyncSessionSnapshot> snapshots;
};
void QuitLoopNow() {
@@ -90,22 +87,6 @@ ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) {
return routes;
}
-// Compare a ModelTypeSet to a ModelTypeInvalidationMap, ignoring
-// state values.
-testing::AssertionResult ModelTypeSetMatchesInvalidationMap(
- ModelTypeSet lhs, const ModelTypeInvalidationMap& rhs) {
- ModelTypeSet rhs_set = ModelTypeInvalidationMapToSet(rhs);
-
- if (!rhs_set.Equals(rhs_set)) {
- return testing::AssertionFailure()
- << "ModelTypeSet: " << ModelTypeSetToString(lhs)
- << " does not match ModelTypeInvalidationMap: "
- << ModelTypeSetToString(rhs_set);
- } else {
- return testing::AssertionSuccess();
- }
-}
-
// Convenient to use in tests wishing to analyze SyncShare calls over time.
static const size_t kMinNumSamples = 5;
class SyncSchedulerTest : public testing::Test {
@@ -124,7 +105,7 @@ class SyncSchedulerTest : public testing::Test {
virtual void SetUp() {
dir_maker_.SetUp();
- syncer_ = new MockSyncer();
+ syncer_ = new testing::StrictMock<MockSyncer>();
delay_ = NULL;
routing_info_[BOOKMARKS] = GROUP_UI;
@@ -187,8 +168,6 @@ class SyncSchedulerTest : public testing::Test {
SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")");
TimeTicks optimal_next_sync = optimal_start + poll_interval * i;
EXPECT_GE(data[i], optimal_next_sync);
- EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC,
- records.snapshots[i].source().updates_source);
}
}
@@ -246,20 +225,19 @@ class SyncSchedulerTest : public testing::Test {
ModelSafeRoutingInfo routing_info_;
};
-void RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record) {
+void RecordSyncShareImpl(SyncShareRecords* record) {
record->times.push_back(TimeTicks::Now());
- record->snapshots.push_back(s->TakeSnapshot());
}
ACTION_P(RecordSyncShare, record) {
- RecordSyncShareImpl(arg0, record);
+ RecordSyncShareImpl(record);
if (base::MessageLoop::current()->is_running())
QuitLoopNow();
return true;
}
ACTION_P2(RecordSyncShareMultiple, record, quit_after) {
- RecordSyncShareImpl(arg0, record);
+ RecordSyncShareImpl(record);
EXPECT_LE(record->times.size(), quit_after);
if (record->times.size() >= quit_after &&
base::MessageLoop::current()->is_running()) {
@@ -286,7 +264,7 @@ TEST_F(SyncSchedulerTest, Nudge) {
EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
- WithArg<2>(RecordSyncShare(&records))))
+ RecordSyncShare(&records)))
.RetiresOnSaturation();
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
@@ -294,13 +272,6 @@ TEST_F(SyncSchedulerTest, Nudge) {
scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
RunLoop();
- ASSERT_EQ(1U, records.snapshots.size());
- EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
- model_types,
- records.snapshots[0].source().types));
- EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
- records.snapshots[0].source().updates_source);
-
Mock::VerifyAndClearExpectations(syncer());
// Make sure a second, later, nudge is unaffected by first (no coalescing).
@@ -309,16 +280,9 @@ TEST_F(SyncSchedulerTest, Nudge) {
model_types.Put(AUTOFILL);
EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
- WithArg<2>(RecordSyncShare(&records2))));
+ RecordSyncShare(&records2)));
scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
RunLoop();
-
- ASSERT_EQ(1U, records2.snapshots.size());
- EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
- model_types,
- records2.snapshots[0].source().types));
- EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
- records2.snapshots[0].source().updates_source);
}
// Make sure a regular config command is scheduled fine in the absence of any
@@ -327,9 +291,9 @@ TEST_F(SyncSchedulerTest, Config) {
SyncShareRecords records;
const ModelTypeSet model_types(BOOKMARKS);
- EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
+ EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
- WithArg<1>(RecordSyncShare(&records))));
+ RecordSyncShare(&records)));
StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
@@ -341,13 +305,6 @@ TEST_F(SyncSchedulerTest, Config) {
base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
ASSERT_EQ(1, counter.times_called());
-
- ASSERT_EQ(1U, records.snapshots.size());
- EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
- model_types,
- records.snapshots[0].source().types));
- EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
- records.snapshots[0].source().updates_source);
}
// Simulate a failure and make sure the config request is retried.
@@ -358,15 +315,12 @@ TEST_F(SyncSchedulerTest, ConfigWithBackingOff) {
SyncShareRecords records;
const ModelTypeSet model_types(BOOKMARKS);
- EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
- .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed),
- WithArg<1>(RecordSyncShare(&records))))
- .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
- WithArg<1>(RecordSyncShare(&records))));
-
StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
- ASSERT_EQ(0U, records.snapshots.size());
+ EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed),
+ RecordSyncShare(&records)));
+
CallbackCounter counter;
ConfigurationParams params(
GetUpdatesCallerInfo::RECONFIGURATION,
@@ -376,16 +330,14 @@ TEST_F(SyncSchedulerTest, ConfigWithBackingOff) {
ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
ASSERT_EQ(0, counter.times_called());
- ASSERT_EQ(1U, records.snapshots.size());
+ Mock::VerifyAndClearExpectations(syncer());
+
+ EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
+ RecordSyncShare(&records)));
RunLoop();
- ASSERT_EQ(2U, records.snapshots.size());
ASSERT_EQ(1, counter.times_called());
- EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
- model_types,
- records.snapshots[1].source().types));
- EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
- records.snapshots[1].source().updates_source);
}
// Issue a nudge when the config has failed. Make sure both the config and
@@ -397,21 +349,12 @@ TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) {
.WillRepeatedly(Return(TimeDelta::FromMilliseconds(50)));
SyncShareRecords records;
- EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
- .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed),
- WithArg<1>(RecordSyncShare(&records))))
- .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed),
- WithArg<1>(RecordSyncShare(&records))))
- .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
- WithArg<1>(RecordSyncShare(&records))));
-
- EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
- .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
- WithArg<2>(RecordSyncShare(&records))));
-
StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
- ASSERT_EQ(0U, records.snapshots.size());
+ // Request a configure and make sure it fails.
+ EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed),
+ RecordSyncShare(&records)));
CallbackCounter counter;
ConfigurationParams params(
GetUpdatesCallerInfo::RECONFIGURATION,
@@ -420,40 +363,31 @@ TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) {
base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
ASSERT_EQ(0, counter.times_called());
- ASSERT_EQ(1U, records.snapshots.size());
+ Mock::VerifyAndClearExpectations(syncer());
+ // Ask for a nudge while dealing with repeated configure failure.
+ EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed),
+ RecordSyncShare(&records)));
scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
RunLoop();
// Note that we're not RunLoop()ing for the NUDGE we just scheduled, but
// for the first retry attempt from the config job (after
// waiting ~+/- 50ms).
- ASSERT_EQ(2U, records.snapshots.size());
+ Mock::VerifyAndClearExpectations(syncer());
ASSERT_EQ(0, counter.times_called());
- EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
- records.snapshots[1].source().updates_source);
+ // Let the next configure retry succeed.
+ EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
+ RecordSyncShare(&records)));
RunLoop();
- // This is the 3rd attempt, which we've set up to SimulateSuccess.
- ASSERT_EQ(3U, records.snapshots.size());
- ASSERT_EQ(1, counter.times_called());
// Now change the mode so nudge can execute.
+ EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
+ RecordSyncShare(&records)));
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
-
- ASSERT_EQ(4U, records.snapshots.size());
-
- EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
- model_types,
- records.snapshots[2].source().types));
- EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
- records.snapshots[2].source().updates_source);
-
- EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
- model_types,
- records.snapshots[3].source().types));
- EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
- records.snapshots[3].source().updates_source);
-
}
// Test that nudges are coalesced.
@@ -463,7 +397,7 @@ TEST_F(SyncSchedulerTest, NudgeCoalescing) {
SyncShareRecords r;
EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
- WithArg<2>(RecordSyncShare(&r))));
+ RecordSyncShare(&r)));
const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES);
TimeDelta delay = zero();
TimeTicks optimal_time = TimeTicks::Now() + delay;
@@ -471,29 +405,17 @@ TEST_F(SyncSchedulerTest, NudgeCoalescing) {
scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE);
RunLoop();
- ASSERT_EQ(1U, r.snapshots.size());
+ ASSERT_EQ(1U, r.times.size());
EXPECT_GE(r.times[0], optimal_time);
- EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
- Union(types1, types2),
- r.snapshots[0].source().types));
- EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
- r.snapshots[0].source().updates_source);
Mock::VerifyAndClearExpectations(syncer());
SyncShareRecords r2;
EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
- WithArg<2>(RecordSyncShare(&r2))));
+ RecordSyncShare(&r2)));
scheduler()->ScheduleLocalNudge(zero(), types3, FROM_HERE);
RunLoop();
-
- ASSERT_EQ(1U, r2.snapshots.size());
- EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
- types3,
- r2.snapshots[0].source().types));
- EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
- r2.snapshots[0].source().updates_source);
}
// Test that nudges are coalesced.
@@ -503,7 +425,7 @@ TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) {
SyncShareRecords r;
EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
- WithArg<2>(RecordSyncShare(&r))));
+ RecordSyncShare(&r)));
ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3;
// Create a huge time delay.
@@ -516,14 +438,10 @@ TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) {
TimeTicks max_time = TimeTicks::Now() + delay;
RunLoop();
-
- // Make sure the sync has happened.
- ASSERT_EQ(1U, r.snapshots.size());
- EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
- Union(types1, types2),
- r.snapshots[0].source().types));
+ Mock::VerifyAndClearExpectations(syncer());
// Make sure the sync happened at the right time.
+ ASSERT_EQ(1U, r.times.size());
EXPECT_GE(r.times[0], min_time);
EXPECT_LE(r.times[0], max_time);
}
@@ -539,16 +457,11 @@ TEST_F(SyncSchedulerTest, NudgeWithStates) {
EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
- WithArg<2>(RecordSyncShare(&records))))
+ RecordSyncShare(&records)))
.RetiresOnSaturation();
scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE);
RunLoop();
- ASSERT_EQ(1U, records.snapshots.size());
- EXPECT_THAT(invalidation_map, Eq(records.snapshots[0].source().types));
- EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
- records.snapshots[0].source().updates_source);
-
Mock::VerifyAndClearExpectations(syncer());
// Make sure a second, later, nudge is unaffected by first (no coalescing).
@@ -557,14 +470,9 @@ TEST_F(SyncSchedulerTest, NudgeWithStates) {
invalidation_map[AUTOFILL].payload = "test2";
EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
- WithArg<2>(RecordSyncShare(&records2))));
+ RecordSyncShare(&records2)));
scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE);
RunLoop();
-
- ASSERT_EQ(1U, records2.snapshots.size());
- EXPECT_THAT(invalidation_map, Eq(records2.snapshots[0].source().types));
- EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
- records2.snapshots[0].source().updates_source);
}
// Test that polling works as expected.
@@ -573,7 +481,7 @@ TEST_F(SyncSchedulerTest, Polling) {
TimeDelta poll_interval(TimeDelta::FromMilliseconds(30));
EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples))
.WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
- WithArg<1>(RecordSyncShareMultiple(&records, kMinNumSamples))));
+ RecordSyncShareMultiple(&records, kMinNumSamples)));
scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval);
@@ -593,7 +501,7 @@ TEST_F(SyncSchedulerTest, PollNotificationsDisabled) {
TimeDelta poll_interval(TimeDelta::FromMilliseconds(30));
EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples))
.WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
- WithArg<1>(RecordSyncShareMultiple(&records, kMinNumSamples))));
+ RecordSyncShareMultiple(&records, kMinNumSamples)));
scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval);
scheduler()->SetNotificationsEnabled(false);
@@ -669,9 +577,9 @@ TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) {
TimeDelta throttle(TimeDelta::FromMinutes(10));
scheduler()->OnReceivedLongPollIntervalUpdate(poll);
- EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
+ EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
.WillOnce(DoAll(
- WithArg<1>(sessions::test_util::SimulateThrottled(throttle)),
+ WithArg<2>(sessions::test_util::SimulateThrottled(throttle)),
Return(true)))
.WillRepeatedly(AddFailureAndQuitLoopNow());
@@ -707,7 +615,7 @@ TEST_F(SyncSchedulerTest, ThrottlingExpiresFromPoll) {
.RetiresOnSaturation();
EXPECT_CALL(*syncer(), PollSyncShare(_,_))
.WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
- WithArg<1>(RecordSyncShareMultiple(&records, kMinNumSamples))));
+ RecordSyncShareMultiple(&records, kMinNumSamples)));
TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1;
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
@@ -754,12 +662,12 @@ TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) {
scheduler()->OnReceivedLongPollIntervalUpdate(poll);
::testing::InSequence seq;
- EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
+ EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
.WillOnce(DoAll(
- WithArg<1>(sessions::test_util::SimulateThrottled(throttle1)),
+ WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)),
Return(true)))
.RetiresOnSaturation();
- EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
+ EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
QuitLoopNowAction()));
@@ -834,14 +742,10 @@ TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) {
throttled_types, throttle1)),
Return(true)))
.RetiresOnSaturation();
- EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
- .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
- WithArg<2>(RecordSyncShare(&records))));
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE);
PumpLoop();
- EXPECT_EQ(0U, records.snapshots.size());
EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types));
// Ignore invalidations for throttled types.
@@ -849,17 +753,20 @@ TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) {
ModelTypeSetToInvalidationMap(throttled_types, "test");
scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE);
PumpLoop();
- EXPECT_EQ(0U, records.snapshots.size());
// Ignore refresh requests for throttled types.
scheduler()->ScheduleLocalRefreshRequest(zero(), throttled_types, FROM_HERE);
PumpLoop();
- EXPECT_EQ(0U, records.snapshots.size());
+
+ Mock::VerifyAndClearExpectations(syncer());
// Local nudges for non-throttled types will trigger a sync.
+ EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
+ .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
+ RecordSyncShare(&records)));
scheduler()->ScheduleLocalNudge(zero(), unthrottled_types, FROM_HERE);
RunLoop();
- EXPECT_EQ(1U, records.snapshots.size());
+ Mock::VerifyAndClearExpectations(syncer());
StopSyncScheduler();
}
@@ -869,10 +776,6 @@ TEST_F(SyncSchedulerTest, ConfigurationMode) {
TimeDelta poll(TimeDelta::FromMilliseconds(15));
SyncShareRecords records;
scheduler()->OnReceivedLongPollIntervalUpdate(poll);
- EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
- .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
- WithArg<1>(RecordSyncShare(&records))))
- .RetiresOnSaturation();
StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
@@ -882,6 +785,10 @@ TEST_F(SyncSchedulerTest, ConfigurationMode) {
const ModelTypeSet config_types(BOOKMARKS);
+ EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
+ RecordSyncShare(&records)))
+ .RetiresOnSaturation();
CallbackCounter counter;
ConfigurationParams params(
GetUpdatesCallerInfo::RECONFIGURATION,
@@ -890,32 +797,20 @@ TEST_F(SyncSchedulerTest, ConfigurationMode) {
base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
ASSERT_EQ(1, counter.times_called());
-
- ASSERT_EQ(1U, records.snapshots.size());
- EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
- config_types,
- records.snapshots[0].source().types));
+ Mock::VerifyAndClearExpectations(syncer());
// Switch to NORMAL_MODE to ensure NUDGES were properly saved and run.
- // SyncSchedulerWhiteboxTest also provides coverage for this, but much
- // more targeted ('whitebox' style).
scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1));
SyncShareRecords records2;
EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
- WithArg<2>(RecordSyncShare(&records2))));
+ RecordSyncShare(&records2)));
// TODO(tim): Figure out how to remove this dangerous need to reset
// routing info between mode switches.
context()->set_routing_info(routing_info());
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
- ASSERT_EQ(1U, records2.snapshots.size());
- EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
- records2.snapshots[0].source().updates_source);
- EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
- nudge_types,
- records2.snapshots[0].source().types));
PumpLoop();
}
@@ -982,7 +877,7 @@ TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) {
// Have the syncer fail to get the encryption key yet succeed in downloading
// updates. Expect this will leave the scheduler in backoff.
TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) {
- EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
+ EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
.WillOnce(DoAll(
Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed),
Return(true)))
@@ -1013,8 +908,8 @@ TEST_F(SyncSchedulerTest, BackoffDropsJobs) {
UseMockDelayProvider();
EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
- .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
- WithArg<2>(RecordSyncShareMultiple(&r, 1U))));
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
+ RecordSyncShareMultiple(&r, 1U)));
EXPECT_CALL(*delay(), GetDelay(_)).
WillRepeatedly(Return(TimeDelta::FromDays(1)));
@@ -1025,10 +920,8 @@ TEST_F(SyncSchedulerTest, BackoffDropsJobs) {
scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE);
RunLoop();
+ // From this point forward, no SyncShare functions should be invoked.
Mock::VerifyAndClearExpectations(syncer());
- ASSERT_EQ(1U, r.snapshots.size());
- EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
- r.snapshots[0].source().updates_source);
// Wait a while (10x poll interval) so a few poll jobs will be attempted.
PumpLoopFor(poll * 10);
@@ -1042,8 +935,6 @@ TEST_F(SyncSchedulerTest, BackoffDropsJobs) {
Mock::VerifyAndClearExpectations(syncer());
Mock::VerifyAndClearExpectations(delay());
- ASSERT_EQ(1U, r.snapshots.size());
-
EXPECT_CALL(*delay(), GetDelay(_)).Times(0);
StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
@@ -1065,7 +956,7 @@ TEST_F(SyncSchedulerTest, BackoffElevation) {
EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)).Times(kMinNumSamples)
.WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
- WithArg<2>(RecordSyncShareMultiple(&r, kMinNumSamples))));
+ RecordSyncShareMultiple(&r, kMinNumSamples)));
const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds);
const TimeDelta second = TimeDelta::FromMilliseconds(2);
@@ -1090,7 +981,7 @@ TEST_F(SyncSchedulerTest, BackoffElevation) {
scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
RunLoop();
- ASSERT_EQ(kMinNumSamples, r.snapshots.size());
+ ASSERT_EQ(kMinNumSamples, r.times.size());
EXPECT_GE(r.times[1] - r.times[0], second);
EXPECT_GE(r.times[2] - r.times[1], third);
EXPECT_GE(r.times[3] - r.times[2], fourth);
@@ -1105,50 +996,49 @@ TEST_F(SyncSchedulerTest, BackoffRelief) {
UseMockDelayProvider();
const TimeDelta backoff = TimeDelta::FromMilliseconds(5);
-
- EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
- .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
- WithArg<2>(RecordSyncShareMultiple(&r, kMinNumSamples))))
- .WillRepeatedly(DoAll(
- Invoke(sessions::test_util::SimulateNormalSuccess),
- WithArg<2>(RecordSyncShareMultiple(&r, kMinNumSamples))));
- EXPECT_CALL(*syncer(), PollSyncShare(_,_))
- .WillRepeatedly(DoAll(
- Invoke(sessions::test_util::SimulatePollSuccess),
- WithArg<1>(RecordSyncShareMultiple(&r, kMinNumSamples))));
EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff));
// Optimal start for the post-backoff poll party.
TimeTicks optimal_start = TimeTicks::Now();
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
- // Run again to wait for polling.
+ // Kick off the test with a failed nudge.
+ EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
+ .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
+ RecordSyncShare(&r)));
scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
RunLoop();
-
- StopSyncScheduler();
-
- EXPECT_EQ(kMinNumSamples, r.times.size());
-
- // The first nudge ran as soon as possible. It failed.
+ Mock::VerifyAndClearExpectations(syncer());
TimeTicks optimal_job_time = optimal_start;
+ ASSERT_EQ(1U, r.times.size());
EXPECT_GE(r.times[0], optimal_job_time);
- EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
- r.snapshots[0].source().updates_source);
- // It was followed by a successful retry nudge shortly afterward.
+ // The retry succeeds.
+ EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
+ .WillOnce(DoAll(
+ Invoke(sessions::test_util::SimulateNormalSuccess),
+ RecordSyncShare(&r)));
+ RunLoop();
+ Mock::VerifyAndClearExpectations(syncer());
optimal_job_time = optimal_job_time + backoff;
+ ASSERT_EQ(2U, r.times.size());
EXPECT_GE(r.times[1], optimal_job_time);
- EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
- r.snapshots[1].source().updates_source);
- // After that, we went back to polling.
- for (size_t i = 2; i < r.snapshots.size(); i++) {
+
+ // Now let the Poll timer do its thing.
+ EXPECT_CALL(*syncer(), PollSyncShare(_,_))
+ .WillRepeatedly(DoAll(
+ Invoke(sessions::test_util::SimulatePollSuccess),
+ RecordSyncShareMultiple(&r, kMinNumSamples)));
+ RunLoop();
+ Mock::VerifyAndClearExpectations(syncer());
+ ASSERT_EQ(kMinNumSamples, r.times.size());
+ for (size_t i = 2; i < r.times.size(); i++) {
optimal_job_time = optimal_job_time + poll;
SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")");
EXPECT_GE(r.times[i], optimal_job_time);
- EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC,
- r.snapshots[i].source().updates_source);
}
+
+ StopSyncScheduler();
}
// Test that poll failures are ignored. They should have no effect on
@@ -1161,9 +1051,9 @@ TEST_F(SyncSchedulerTest, TransientPollFailure) {
EXPECT_CALL(*syncer(), PollSyncShare(_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollFailed),
- WithArg<1>(RecordSyncShare(&r))))
+ RecordSyncShare(&r)))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
- WithArg<1>(RecordSyncShare(&r))));
+ RecordSyncShare(&r)));
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
@@ -1261,7 +1151,7 @@ TEST_F(SyncSchedulerTest, ConnectionChangeCanaryPreemptedByNudge) {
// Tests that we don't crash trying to run two canaries at once if we receive
// extra connection status change notifications. See crbug.com/190085.
TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) {
- EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
+ EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
.WillRepeatedly(DoAll(
Invoke(sessions::test_util::SimulateConfigureConnectionFailure),
Return(true)));
@@ -1292,7 +1182,7 @@ TEST_F(SyncSchedulerTest, PollFromCanaryAfterAuthError) {
::testing::InSequence seq;
EXPECT_CALL(*syncer(), PollSyncShare(_,_))
.WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
- WithArg<1>(RecordSyncShareMultiple(&records, kMinNumSamples))));
+ RecordSyncShareMultiple(&records, kMinNumSamples)));
connection()->SetServerStatus(HttpResponse::SYNC_AUTH_ERROR);
StartSyncScheduler(SyncScheduler::NORMAL_MODE);
@@ -1305,7 +1195,7 @@ TEST_F(SyncSchedulerTest, PollFromCanaryAfterAuthError) {
// poll once more
EXPECT_CALL(*syncer(), PollSyncShare(_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
- WithArg<1>(RecordSyncShare(&records))));
+ RecordSyncShare(&records)));
scheduler()->OnCredentialsUpdated();
connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK);
StopSyncScheduler();
« no previous file with comments | « sync/engine/sync_scheduler_impl.cc ('k') | sync/engine/syncer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698