Index: sync/engine/non_blocking_type_processor_unittest.cc |
diff --git a/sync/engine/non_blocking_type_processor_unittest.cc b/sync/engine/non_blocking_type_processor_unittest.cc |
index 9ab6ca320f3828e8288d7a762bdfb5348567babb..3a3ca5c59e725d2cd010da4479a943fb8eedfbad 100644 |
--- a/sync/engine/non_blocking_type_processor_unittest.cc |
+++ b/sync/engine/non_blocking_type_processor_unittest.cc |
@@ -134,14 +134,21 @@ class NonBlockingTypeProcessorTest : public ::testing::Test { |
NonBlockingTypeProcessorTest(); |
virtual ~NonBlockingTypeProcessorTest(); |
- // Explicit initialization step. Kept separate to allow tests to inject |
- // on-disk state before the test begins. |
- void Initialize(); |
+ // Initialize with no local state. The processor will be unable to commit |
+ // until it receives notification that initial sync has completed. |
+ void FirstTimeInitialize(); |
+ |
+ // Initialize to a "ready-to-commit" state. |
+ void InitializeToReadyState(); |
// Local data modification. Emulates signals from the model thread. |
void WriteItem(const std::string& tag, const std::string& value); |
void DeleteItem(const std::string& tag); |
+ // Emulates an "initial sync done" message from the |
+ // NonBlockingTypeProcessorCore. |
+ void OnInitialSyncDone(); |
+ |
// Emulate updates from the server. |
// This harness has some functionality to help emulate server behavior. |
// See the definitions of these methods for more information. |
@@ -190,11 +197,20 @@ NonBlockingTypeProcessorTest::NonBlockingTypeProcessorTest() |
NonBlockingTypeProcessorTest::~NonBlockingTypeProcessorTest() { |
} |
-void NonBlockingTypeProcessorTest::Initialize() { |
+void NonBlockingTypeProcessorTest::FirstTimeInitialize() { |
processor_->Enable(mock_sync_core_proxy_->Clone()); |
mock_processor_core_ = mock_sync_core_proxy_->GetMockProcessorCore(); |
} |
+void NonBlockingTypeProcessorTest::InitializeToReadyState() { |
+ // TODO(rlarocque): This should be updated to inject on-disk state. |
+ // At the time this code was written, there was no support for on-disk |
+ // state so this was the only way to inject a data_type_state into |
+ // the |processor_|. |
+ FirstTimeInitialize(); |
+ OnInitialSyncDone(); |
+} |
+ |
void NonBlockingTypeProcessorTest::WriteItem(const std::string& tag, |
const std::string& value) { |
const std::string tag_hash = GenerateTagHash(tag); |
@@ -205,6 +221,13 @@ void NonBlockingTypeProcessorTest::DeleteItem(const std::string& tag) { |
processor_->Delete(tag); |
} |
+void NonBlockingTypeProcessorTest::OnInitialSyncDone() { |
+ data_type_state_.initial_sync_done = true; |
+ UpdateResponseDataList empty_update_list; |
+ |
+ processor_->OnUpdateReceived(data_type_state_, empty_update_list); |
+} |
+ |
void NonBlockingTypeProcessorTest::UpdateFromServer(int64 version_offset, |
const std::string& tag, |
const std::string& value) { |
@@ -385,7 +408,7 @@ CommitRequestData NonBlockingTypeProcessorTest::GetLatestCommitRequestForTag( |
// Creates a new item locally. |
// Thoroughly tests the data generated by a local item creation. |
TEST_F(NonBlockingTypeProcessorTest, CreateLocalItem) { |
- Initialize(); |
+ InitializeToReadyState(); |
EXPECT_EQ(0U, GetNumCommitRequestLists()); |
WriteItem("tag1", "value1"); |
@@ -396,7 +419,7 @@ TEST_F(NonBlockingTypeProcessorTest, CreateLocalItem) { |
const CommitRequestData& tag1_data = GetLatestCommitRequestForTag("tag1"); |
EXPECT_TRUE(tag1_data.id.empty()); |
- EXPECT_EQ(0, tag1_data.base_version); |
+ EXPECT_EQ(kUncommittedVersion, tag1_data.base_version); |
EXPECT_FALSE(tag1_data.ctime.is_null()); |
EXPECT_FALSE(tag1_data.mtime.is_null()); |
EXPECT_EQ("tag1", tag1_data.non_unique_name); |
@@ -408,7 +431,7 @@ TEST_F(NonBlockingTypeProcessorTest, CreateLocalItem) { |
// Creates a new local item then modifies it. |
// Thoroughly tests data generated by modification of server-unknown item. |
TEST_F(NonBlockingTypeProcessorTest, CreateAndModifyLocalItem) { |
- Initialize(); |
+ InitializeToReadyState(); |
EXPECT_EQ(0U, GetNumCommitRequestLists()); |
WriteItem("tag1", "value1"); |
@@ -428,7 +451,7 @@ TEST_F(NonBlockingTypeProcessorTest, CreateAndModifyLocalItem) { |
// Perform a thorough examination of the update-generated request. |
EXPECT_TRUE(tag1_v2_data.id.empty()); |
- EXPECT_EQ(0, tag1_v2_data.base_version); |
+ EXPECT_EQ(kUncommittedVersion, tag1_v2_data.base_version); |
EXPECT_FALSE(tag1_v2_data.ctime.is_null()); |
EXPECT_FALSE(tag1_v2_data.mtime.is_null()); |
EXPECT_EQ("tag1", tag1_v2_data.non_unique_name); |
@@ -440,7 +463,7 @@ TEST_F(NonBlockingTypeProcessorTest, CreateAndModifyLocalItem) { |
// Deletes an item we've never seen before. |
// Should have no effect and not crash. |
TEST_F(NonBlockingTypeProcessorTest, DeleteUnknown) { |
- Initialize(); |
+ InitializeToReadyState(); |
DeleteItem("tag1"); |
EXPECT_EQ(0U, GetNumCommitRequestLists()); |
@@ -452,7 +475,7 @@ TEST_F(NonBlockingTypeProcessorTest, DeleteUnknown) { |
// server-unknown as far as the model thread is concerned. That behavior |
// is race-dependent; other tests are used to test other races. |
TEST_F(NonBlockingTypeProcessorTest, DeleteServerUnknown) { |
- Initialize(); |
+ InitializeToReadyState(); |
WriteItem("tag1", "value1"); |
EXPECT_EQ(1U, GetNumCommitRequestLists()); |
@@ -467,7 +490,7 @@ TEST_F(NonBlockingTypeProcessorTest, DeleteServerUnknown) { |
EXPECT_GT(tag1_v2_data.sequence_number, tag1_v1_data.sequence_number); |
EXPECT_TRUE(tag1_v2_data.id.empty()); |
- EXPECT_EQ(0, tag1_v2_data.base_version); |
+ EXPECT_EQ(kUncommittedVersion, tag1_v2_data.base_version); |
EXPECT_TRUE(tag1_v2_data.deleted); |
} |
@@ -477,7 +500,7 @@ TEST_F(NonBlockingTypeProcessorTest, DeleteServerUnknown) { |
// successfully commits it, but, before the commit response is picked up |
// by the model thread, the item is deleted by the model thread. |
TEST_F(NonBlockingTypeProcessorTest, DeleteServerUnknown_RacyCommitResponse) { |
- Initialize(); |
+ InitializeToReadyState(); |
WriteItem("tag1", "value1"); |
EXPECT_EQ(1U, GetNumCommitRequestLists()); |
@@ -501,7 +524,7 @@ TEST_F(NonBlockingTypeProcessorTest, DeleteServerUnknown_RacyCommitResponse) { |
// Creates two different sync items. |
// Verifies that the second has no effect on the first. |
TEST_F(NonBlockingTypeProcessorTest, TwoIndependentItems) { |
- Initialize(); |
+ InitializeToReadyState(); |
EXPECT_EQ(0U, GetNumCommitRequestLists()); |
WriteItem("tag1", "value1"); |
@@ -519,6 +542,20 @@ TEST_F(NonBlockingTypeProcessorTest, TwoIndependentItems) { |
ASSERT_TRUE(HasCommitRequestForTag("tag2")); |
} |
+// Starts the processor with no local state. |
+// Verify that it waits until initial sync is complete before requesting |
+// commits. |
+TEST_F(NonBlockingTypeProcessorTest, NoCommitsUntilInitialSyncDone) { |
+ FirstTimeInitialize(); |
+ |
+ WriteItem("tag1", "value1"); |
+ EXPECT_EQ(0U, GetNumCommitRequestLists()); |
+ |
+ OnInitialSyncDone(); |
+ EXPECT_EQ(1U, GetNumCommitRequestLists()); |
+ EXPECT_TRUE(HasCommitRequestForTag("tag1")); |
+} |
+ |
// TODO(rlarocque): Add more testing of non_unique_name fields. |
} // namespace syncer |