Commit 4d75c829 authored by maxbogue's avatar maxbogue Committed by Commit bot

[Sync] Test that MergeSyncData is not called on subsequent starts.

BUG=

Review-Url: https://codereview.chromium.org/2363853002
Cr-Commit-Position: refs/heads/master@{#420723}
parent 9f70a54d
...@@ -170,25 +170,6 @@ class SharedModelTypeProcessorTest : public ::testing::Test, ...@@ -170,25 +170,6 @@ class SharedModelTypeProcessorTest : public ::testing::Test,
worker_ = nullptr; worker_ = nullptr;
} }
// Simulates an initial GetUpdates response from the worker with |updates|.
void OnInitialSyncDone(UpdateResponseDataList updates) {
DataTypeState data_type_state(db_.data_type_state());
data_type_state.set_initial_sync_done(true);
type_processor()->OnUpdateReceived(data_type_state, updates);
}
// Overloaded form with no updates.
void OnInitialSyncDone() { OnInitialSyncDone(UpdateResponseDataList()); }
// Overloaded form that constructs an update for a single entity.
void OnInitialSyncDone(const std::string& key, const std::string& value) {
UpdateResponseDataList updates;
UpdateResponseData update;
update.entity = GenerateEntityData(key, value)->PassToPtr();
updates.push_back(update);
OnInitialSyncDone(updates);
}
// Return the number of entities the processor has metadata for. // Return the number of entities the processor has metadata for.
size_t ProcessorEntityCount() const { size_t ProcessorEntityCount() const {
DCHECK(type_processor()); DCHECK(type_processor());
...@@ -219,6 +200,8 @@ class SharedModelTypeProcessorTest : public ::testing::Test, ...@@ -219,6 +200,8 @@ class SharedModelTypeProcessorTest : public ::testing::Test,
return error_handler_; return error_handler_;
} }
int merge_call_count() const { return merge_call_count_; }
private: private:
void CheckPostConditions() override { void CheckPostConditions() override {
FakeModelTypeService::CheckPostConditions(); FakeModelTypeService::CheckPostConditions();
...@@ -248,6 +231,12 @@ class SharedModelTypeProcessorTest : public ::testing::Test, ...@@ -248,6 +231,12 @@ class SharedModelTypeProcessorTest : public ::testing::Test,
// FakeModelTypeService overrides. // FakeModelTypeService overrides.
syncer::SyncError MergeSyncData(std::unique_ptr<MetadataChangeList> mcl,
EntityDataMap entity_data_map) override {
merge_call_count_++;
return FakeModelTypeService::MergeSyncData(std::move(mcl), entity_data_map);
}
void CaptureDataCallback(DataCallback callback, void CaptureDataCallback(DataCallback callback,
syncer::SyncError error, syncer::SyncError error,
std::unique_ptr<DataBatch> data) { std::unique_ptr<DataBatch> data) {
...@@ -284,6 +273,9 @@ class SharedModelTypeProcessorTest : public ::testing::Test, ...@@ -284,6 +273,9 @@ class SharedModelTypeProcessorTest : public ::testing::Test,
// The error to expect in OnReadyToConnect(). // The error to expect in OnReadyToConnect().
syncer::SyncError::ErrorType expected_start_error_ = syncer::SyncError::UNSET; syncer::SyncError::ErrorType expected_start_error_ = syncer::SyncError::UNSET;
// The number of times MergeSyncData has been called.
int merge_call_count_ = 0;
}; };
// Test that an initial sync handles local and remote items properly. // Test that an initial sync handles local and remote items properly.
...@@ -301,8 +293,10 @@ TEST_F(SharedModelTypeProcessorTest, InitialSync) { ...@@ -301,8 +293,10 @@ TEST_F(SharedModelTypeProcessorTest, InitialSync) {
EXPECT_EQ(0U, ProcessorEntityCount()); EXPECT_EQ(0U, ProcessorEntityCount());
EXPECT_EQ(0U, worker()->GetNumPendingCommits()); EXPECT_EQ(0U, worker()->GetNumPendingCommits());
EXPECT_EQ(0, merge_call_count());
// Initial sync with one server item. // Initial sync with one server item.
OnInitialSyncDone(kKey2, kValue2); worker()->UpdateFromServer(kHash2, GenerateSpecifics(kKey2, kValue2));
EXPECT_EQ(1, merge_call_count());
// Now have data and metadata for both items, as well as a commit request for // Now have data and metadata for both items, as well as a commit request for
// the local item. // the local item.
...@@ -314,6 +308,24 @@ TEST_F(SharedModelTypeProcessorTest, InitialSync) { ...@@ -314,6 +308,24 @@ TEST_F(SharedModelTypeProcessorTest, InitialSync) {
worker()->ExpectPendingCommits({kHash1}); worker()->ExpectPendingCommits({kHash1});
} }
// Test that subsequent starts don't call MergeSyncData.
TEST_F(SharedModelTypeProcessorTest, NonInitialSync) {
// This sets initial_sync_done to true.
InitializeToMetadataLoaded();
// Write an item before sync connects.
WriteItem(kKey1, kValue1);
EXPECT_EQ(1U, db().data_count());
EXPECT_EQ(1U, db().metadata_count());
// Check that data coming from sync is treated as a normal GetUpdates.
OnSyncStarting();
worker()->UpdateFromServer(kHash2, GenerateSpecifics(kKey2, kValue2));
EXPECT_EQ(0, merge_call_count());
EXPECT_EQ(2U, db().data_count());
EXPECT_EQ(2U, db().metadata_count());
}
// Test that an error during the merge is propagated to the error handler. // Test that an error during the merge is propagated to the error handler.
TEST_F(SharedModelTypeProcessorTest, InitialSyncError) { TEST_F(SharedModelTypeProcessorTest, InitialSyncError) {
CreateChangeProcessor(); CreateChangeProcessor();
...@@ -322,7 +334,7 @@ TEST_F(SharedModelTypeProcessorTest, InitialSyncError) { ...@@ -322,7 +334,7 @@ TEST_F(SharedModelTypeProcessorTest, InitialSyncError) {
SetServiceError(syncer::SyncError::DATATYPE_ERROR); SetServiceError(syncer::SyncError::DATATYPE_ERROR);
error_handler()->ExpectError(syncer::SyncError::DATATYPE_ERROR); error_handler()->ExpectError(syncer::SyncError::DATATYPE_ERROR);
OnInitialSyncDone(); worker()->UpdateFromServer();
} }
// Test that errors before it's called are passed to |start_callback| correctly. // Test that errors before it's called are passed to |start_callback| correctly.
...@@ -1078,7 +1090,7 @@ TEST_F(SharedModelTypeProcessorTest, Disable) { ...@@ -1078,7 +1090,7 @@ TEST_F(SharedModelTypeProcessorTest, Disable) {
CreateChangeProcessor(); CreateChangeProcessor();
OnMetadataLoaded(); OnMetadataLoaded();
OnSyncStarting(); OnSyncStarting();
OnInitialSyncDone(); worker()->UpdateFromServer();
// Once we're ready to commit, all three local items should consider // Once we're ready to commit, all three local items should consider
// themselves uncommitted and pending for commit. // themselves uncommitted and pending for commit.
......
...@@ -21,7 +21,9 @@ namespace { ...@@ -21,7 +21,9 @@ namespace {
MockModelTypeWorker::MockModelTypeWorker( MockModelTypeWorker::MockModelTypeWorker(
const sync_pb::DataTypeState& data_type_state, const sync_pb::DataTypeState& data_type_state,
ModelTypeProcessor* processor) ModelTypeProcessor* processor)
: data_type_state_(data_type_state), processor_(processor) {} : data_type_state_(data_type_state), processor_(processor) {
data_type_state_.set_initial_sync_done(true);
}
MockModelTypeWorker::~MockModelTypeWorker() {} MockModelTypeWorker::~MockModelTypeWorker() {}
...@@ -88,6 +90,10 @@ void MockModelTypeWorker::ExpectPendingCommits( ...@@ -88,6 +90,10 @@ void MockModelTypeWorker::ExpectPendingCommits(
} }
} }
void MockModelTypeWorker::UpdateFromServer() {
processor_->OnUpdateReceived(data_type_state_, UpdateResponseDataList());
}
void MockModelTypeWorker::UpdateFromServer( void MockModelTypeWorker::UpdateFromServer(
const std::string& tag_hash, const std::string& tag_hash,
const sync_pb::EntitySpecifics& specifics) { const sync_pb::EntitySpecifics& specifics) {
...@@ -107,10 +113,10 @@ void MockModelTypeWorker::UpdateFromServer( ...@@ -107,10 +113,10 @@ void MockModelTypeWorker::UpdateFromServer(
const sync_pb::EntitySpecifics& specifics, const sync_pb::EntitySpecifics& specifics,
int64_t version_offset, int64_t version_offset,
const std::string& ekn) { const std::string& ekn) {
UpdateResponseDataList update; UpdateResponseDataList updates;
update.push_back( updates.push_back(
GenerateUpdateData(tag_hash, specifics, version_offset, ekn)); GenerateUpdateData(tag_hash, specifics, version_offset, ekn));
processor_->OnUpdateReceived(data_type_state_, update); processor_->OnUpdateReceived(data_type_state_, updates);
} }
UpdateResponseData MockModelTypeWorker::GenerateUpdateData( UpdateResponseData MockModelTypeWorker::GenerateUpdateData(
......
...@@ -53,9 +53,10 @@ class MockModelTypeWorker : public CommitQueue { ...@@ -53,9 +53,10 @@ class MockModelTypeWorker : public CommitQueue {
// length one. // length one.
void ExpectPendingCommits(const std::vector<std::string>& tag_hashes); void ExpectPendingCommits(const std::vector<std::string>& tag_hashes);
// Trigger an update from the server containing a single entity. See // Trigger an update from the server. See GenerateUpdateData for parameter
// GenerateUpdateData for parameter descriptions. |version_offset| defaults to // descriptions. |version_offset| defaults to 1 and |ekn| defaults to the
// 1 and |ekn| defaults to the current encryption key name the worker has. // current encryption key name the worker has.
void UpdateFromServer();
void UpdateFromServer(const std::string& tag_hash, void UpdateFromServer(const std::string& tag_hash,
const sync_pb::EntitySpecifics& specifics); const sync_pb::EntitySpecifics& specifics);
void UpdateFromServer(const std::string& tag_hash, void UpdateFromServer(const std::string& tag_hash,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment