OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <list> | 10 #include <list> |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 context_->set_routing_info(routing_info); | 454 context_->set_routing_info(routing_info); |
455 } | 455 } |
456 | 456 |
457 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); | 457 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); |
458 } | 458 } |
459 | 459 |
460 Cryptographer* GetCryptographer(syncable::BaseTransaction* trans) { | 460 Cryptographer* GetCryptographer(syncable::BaseTransaction* trans) { |
461 return directory()->GetCryptographer(trans); | 461 return directory()->GetCryptographer(trans); |
462 } | 462 } |
463 | 463 |
| 464 // Configures SyncSessionContext and NudgeTracker so Syncer won't call |
| 465 // GetUpdates prior to Commit. This method can be used to ensure a Commit is |
| 466 // not preceeded by GetUpdates. |
| 467 void ConfigureNoGetUpdatesRequired() { |
| 468 context_->set_server_enabled_pre_commit_update_avoidance(true); |
| 469 nudge_tracker_.OnInvalidationsEnabled(); |
| 470 nudge_tracker_.RecordSuccessfulSyncCycle(); |
| 471 |
| 472 ASSERT_FALSE(context_->ShouldFetchUpdatesBeforeCommit()); |
| 473 ASSERT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); |
| 474 } |
| 475 |
464 base::MessageLoop message_loop_; | 476 base::MessageLoop message_loop_; |
465 | 477 |
466 // Some ids to aid tests. Only the root one's value is specific. The rest | 478 // Some ids to aid tests. Only the root one's value is specific. The rest |
467 // are named for test clarity. | 479 // are named for test clarity. |
468 // TODO(chron): Get rid of these inbuilt IDs. They only make it | 480 // TODO(chron): Get rid of these inbuilt IDs. They only make it |
469 // more confusing. | 481 // more confusing. |
470 syncable::Id root_id_; | 482 syncable::Id root_id_; |
471 syncable::Id parent_id_; | 483 syncable::Id parent_id_; |
472 syncable::Id child_id_; | 484 syncable::Id child_id_; |
473 | 485 |
(...skipping 2039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2513 mock_server_->set_conflict_n_commits(1); | 2525 mock_server_->set_conflict_n_commits(1); |
2514 SyncShareNudge(); | 2526 SyncShareNudge(); |
2515 | 2527 |
2516 // We should stop looping at the first sign of trouble. | 2528 // We should stop looping at the first sign of trouble. |
2517 EXPECT_EQ(1U, mock_server_->commit_messages().size()); | 2529 EXPECT_EQ(1U, mock_server_->commit_messages().size()); |
2518 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1), | 2530 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1), |
2519 directory()->unsynced_entity_count()); | 2531 directory()->unsynced_entity_count()); |
2520 } | 2532 } |
2521 | 2533 |
2522 // Tests that sending debug info events works. | 2534 // Tests that sending debug info events works. |
2523 TEST_F(SyncerTest, SendDebugInfoEvents_HappyCase) { | 2535 TEST_F(SyncerTest, SendDebugInfoEventsOnGetUpdates_HappyCase) { |
2524 debug_info_getter_->AddDebugEvent(); | 2536 debug_info_getter_->AddDebugEvent(); |
2525 debug_info_getter_->AddDebugEvent(); | 2537 debug_info_getter_->AddDebugEvent(); |
2526 | 2538 |
2527 SyncShareNudge(); | 2539 SyncShareNudge(); |
2528 | 2540 |
2529 // Verify we received one request with two debug info events. | 2541 // Verify we received one GetUpdates request with two debug info events. |
2530 EXPECT_EQ(1U, mock_server_->requests().size()); | 2542 EXPECT_EQ(1U, mock_server_->requests().size()); |
2531 EXPECT_EQ(2, mock_server_->requests().back().debug_info().events_size()); | 2543 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); |
| 2544 EXPECT_EQ(2, mock_server_->last_request().debug_info().events_size()); |
2532 | 2545 |
2533 SyncShareNudge(); | 2546 SyncShareNudge(); |
2534 | 2547 |
2535 // See that we received another request, but that it contains no debug info | 2548 // See that we received another GetUpdates request, but that it contains no |
2536 // events. | 2549 // debug info events. |
2537 EXPECT_EQ(2U, mock_server_->requests().size()); | 2550 EXPECT_EQ(2U, mock_server_->requests().size()); |
2538 EXPECT_EQ(0, mock_server_->requests().back().debug_info().events_size()); | 2551 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); |
| 2552 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size()); |
2539 | 2553 |
2540 debug_info_getter_->AddDebugEvent(); | 2554 debug_info_getter_->AddDebugEvent(); |
2541 | 2555 |
2542 SyncShareNudge(); | 2556 SyncShareNudge(); |
2543 | 2557 |
2544 // See that we received another request and it contains one debug info event. | 2558 // See that we received another GetUpdates request and it contains one debug |
| 2559 // info event. |
2545 EXPECT_EQ(3U, mock_server_->requests().size()); | 2560 EXPECT_EQ(3U, mock_server_->requests().size()); |
2546 EXPECT_EQ(1, mock_server_->requests().back().debug_info().events_size()); | 2561 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); |
| 2562 EXPECT_EQ(1, mock_server_->last_request().debug_info().events_size()); |
2547 } | 2563 } |
2548 | 2564 |
2549 // Tests that debug info events are dropped on server error. | 2565 // Tests that debug info events are dropped on server error. |
2550 TEST_F(SyncerTest, SendDebugInfoEvents_PostFailsDontDrop) { | 2566 TEST_F(SyncerTest, SendDebugInfoEventsOnGetUpdates_PostFailsDontDrop) { |
2551 debug_info_getter_->AddDebugEvent(); | 2567 debug_info_getter_->AddDebugEvent(); |
2552 debug_info_getter_->AddDebugEvent(); | 2568 debug_info_getter_->AddDebugEvent(); |
2553 | 2569 |
2554 mock_server_->FailNextPostBufferToPathCall(); | 2570 mock_server_->FailNextPostBufferToPathCall(); |
2555 SyncShareNudge(); | 2571 SyncShareNudge(); |
2556 | 2572 |
2557 // Verify we attempted to send one request with two debug info events. | 2573 // Verify we attempted to send one GetUpdates request with two debug info |
| 2574 // events. |
2558 EXPECT_EQ(1U, mock_server_->requests().size()); | 2575 EXPECT_EQ(1U, mock_server_->requests().size()); |
2559 EXPECT_EQ(2, mock_server_->requests().back().debug_info().events_size()); | 2576 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); |
| 2577 EXPECT_EQ(2, mock_server_->last_request().debug_info().events_size()); |
2560 | 2578 |
2561 SyncShareNudge(); | 2579 SyncShareNudge(); |
2562 | 2580 |
2563 // See that the client resent the two debug info events. | 2581 // See that the client resent the two debug info events. |
2564 EXPECT_EQ(2U, mock_server_->requests().size()); | 2582 EXPECT_EQ(2U, mock_server_->requests().size()); |
2565 EXPECT_EQ(2, mock_server_->requests().back().debug_info().events_size()); | 2583 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); |
| 2584 EXPECT_EQ(2, mock_server_->last_request().debug_info().events_size()); |
2566 | 2585 |
2567 // The previous send was successful so this next one shouldn't generate any | 2586 // The previous send was successful so this next one shouldn't generate any |
2568 // debug info events. | 2587 // debug info events. |
2569 SyncShareNudge(); | 2588 SyncShareNudge(); |
2570 EXPECT_EQ(3U, mock_server_->requests().size()); | 2589 EXPECT_EQ(3U, mock_server_->requests().size()); |
2571 EXPECT_EQ(0, mock_server_->requests().back().debug_info().events_size()); | 2590 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); |
| 2591 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size()); |
| 2592 } |
| 2593 |
| 2594 // Tests that sending debug info events on Commit works. |
| 2595 TEST_F(SyncerTest, SendDebugInfoEventsOnCommit_HappyCase) { |
| 2596 // Make sure GetUpdate isn't call as it would "steal" debug info events before |
| 2597 // Commit has a chance to send them. |
| 2598 ConfigureNoGetUpdatesRequired(); |
| 2599 |
| 2600 // Generate a debug info event and trigger a commit. |
| 2601 debug_info_getter_->AddDebugEvent(); |
| 2602 CreateUnsyncedDirectory("X", "id_X"); |
| 2603 SyncShareNudge(); |
| 2604 |
| 2605 // Verify that the last request received is a Commit and that it contains a |
| 2606 // debug info event. |
| 2607 EXPECT_EQ(1U, mock_server_->requests().size()); |
| 2608 ASSERT_TRUE(mock_server_->last_request().has_commit()); |
| 2609 EXPECT_EQ(1, mock_server_->last_request().debug_info().events_size()); |
| 2610 |
| 2611 // Generate another commit, but no debug info event. |
| 2612 CreateUnsyncedDirectory("Y", "id_Y"); |
| 2613 SyncShareNudge(); |
| 2614 |
| 2615 // See that it was received and contains no debug info events. |
| 2616 EXPECT_EQ(2U, mock_server_->requests().size()); |
| 2617 ASSERT_TRUE(mock_server_->last_request().has_commit()); |
| 2618 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size()); |
| 2619 } |
| 2620 |
| 2621 // Tests that debug info events are not dropped on server error. |
| 2622 TEST_F(SyncerTest, SendDebugInfoEventsOnCommit_PostFailsDontDrop) { |
| 2623 // Make sure GetUpdate isn't call as it would "steal" debug info events before |
| 2624 // Commit has a chance to send them. |
| 2625 ConfigureNoGetUpdatesRequired(); |
| 2626 |
| 2627 mock_server_->FailNextPostBufferToPathCall(); |
| 2628 |
| 2629 // Generate a debug info event and trigger a commit. |
| 2630 debug_info_getter_->AddDebugEvent(); |
| 2631 CreateUnsyncedDirectory("X", "id_X"); |
| 2632 SyncShareNudge(); |
| 2633 |
| 2634 // Verify that the last request sent is a Commit and that it contains a debug |
| 2635 // info event. |
| 2636 EXPECT_EQ(1U, mock_server_->requests().size()); |
| 2637 ASSERT_TRUE(mock_server_->last_request().has_commit()); |
| 2638 EXPECT_EQ(1, mock_server_->last_request().debug_info().events_size()); |
| 2639 |
| 2640 // Try again. |
| 2641 SyncShareNudge(); |
| 2642 |
| 2643 // Verify that we've received another Commit and that it contains a debug info |
| 2644 // event (just like the previous one). |
| 2645 EXPECT_EQ(2U, mock_server_->requests().size()); |
| 2646 ASSERT_TRUE(mock_server_->last_request().has_commit()); |
| 2647 EXPECT_EQ(1, mock_server_->last_request().debug_info().events_size()); |
| 2648 |
| 2649 // Generate another commit and try again. |
| 2650 CreateUnsyncedDirectory("Y", "id_Y"); |
| 2651 SyncShareNudge(); |
| 2652 |
| 2653 // See that it was received and contains no debug info events. |
| 2654 EXPECT_EQ(3U, mock_server_->requests().size()); |
| 2655 ASSERT_TRUE(mock_server_->last_request().has_commit()); |
| 2656 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size()); |
2572 } | 2657 } |
2573 | 2658 |
2574 TEST_F(SyncerTest, HugeConflict) { | 2659 TEST_F(SyncerTest, HugeConflict) { |
2575 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. | 2660 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. |
2576 | 2661 |
2577 syncable::Id parent_id = ids_.NewServerId(); | 2662 syncable::Id parent_id = ids_.NewServerId(); |
2578 syncable::Id last_id = parent_id; | 2663 syncable::Id last_id = parent_id; |
2579 vector<syncable::Id> tree_ids; | 2664 vector<syncable::Id> tree_ids; |
2580 | 2665 |
2581 // Create a lot of updates for which the parent does not exist yet. | 2666 // Create a lot of updates for which the parent does not exist yet. |
(...skipping 2132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4714 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 4799 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
4715 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 4800 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
4716 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 4801 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
4717 } else { | 4802 } else { |
4718 EXPECT_TRUE(final_monitor_records.empty()) | 4803 EXPECT_TRUE(final_monitor_records.empty()) |
4719 << "Should not restore records after successful bookmark commit."; | 4804 << "Should not restore records after successful bookmark commit."; |
4720 } | 4805 } |
4721 } | 4806 } |
4722 | 4807 |
4723 } // namespace syncer | 4808 } // namespace syncer |
OLD | NEW |