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

Side by Side Diff: sync/engine/syncer_unittest.cc

Issue 1273303002: Measuring data use of different ModelTypes in Sync Service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@NewServices
Patch Set: Updating the recording macro. Created 5 years, 4 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 unified diff | Download patch
OLDNEW
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>
11 #include <map> 11 #include <map>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/bind_helpers.h" 16 #include "base/bind_helpers.h"
17 #include "base/callback.h" 17 #include "base/callback.h"
18 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
19 #include "base/location.h" 19 #include "base/location.h"
20 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
21 #include "base/message_loop/message_loop.h" 21 #include "base/message_loop/message_loop.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/test/histogram_tester.h"
23 #include "base/time/time.h" 24 #include "base/time/time.h"
24 #include "build/build_config.h" 25 #include "build/build_config.h"
25 #include "sync/engine/backoff_delay_provider.h" 26 #include "sync/engine/backoff_delay_provider.h"
26 #include "sync/engine/get_commit_ids.h" 27 #include "sync/engine/get_commit_ids.h"
27 #include "sync/engine/net/server_connection_manager.h" 28 #include "sync/engine/net/server_connection_manager.h"
28 #include "sync/engine/sync_scheduler_impl.h" 29 #include "sync/engine/sync_scheduler_impl.h"
29 #include "sync/engine/syncer.h" 30 #include "sync/engine/syncer.h"
30 #include "sync/engine/syncer_proto_util.h" 31 #include "sync/engine/syncer_proto_util.h"
31 #include "sync/internal_api/public/base/cancelation_signal.h" 32 #include "sync/internal_api/public/base/cancelation_signal.h"
32 #include "sync/internal_api/public/base/model_type.h" 33 #include "sync/internal_api/public/base/model_type.h"
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 EXPECT_TRUE(SyncShareNudge()); 660 EXPECT_TRUE(SyncShareNudge());
660 { 661 {
661 // It should have been committed. 662 // It should have been committed.
662 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 663 syncable::ReadTransaction rtrans(FROM_HERE, directory());
663 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); 664 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
664 ASSERT_TRUE(entryA.good()); 665 ASSERT_TRUE(entryA.good());
665 EXPECT_FALSE(entryA.GetIsUnsynced()); 666 EXPECT_FALSE(entryA.GetIsUnsynced());
666 } 667 }
667 } 668 }
668 669
670 // This test has three steps. In the first step, a BOOKMARK update is received.
671 // In the next step, syncing BOOKMARKS is disabled, so no BOOKMARK is sent or
672 // received. In the last step, a BOOKMARK update is committed.
673 TEST_F(SyncerTest, DataUseHistogramsTest) {
674 base::HistogramTester histogram_tester;
675 sync_pb::EntitySpecifics bookmark_data;
676 AddDefaultFieldValue(BOOKMARKS, &bookmark_data);
677
678 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10,
679 foreign_cache_guid(), "-1");
680 int download_bytes_bookmark = 0;
681 vector<int> progress_bookmark = {0, 0, 0};
Nicolas Zea 2015/08/19 22:01:51 nit: std:: here and below
amohammadkhan 2015/08/20 00:20:13 Done.
682 vector<int> progress_all = {0, 0, 0};
sclittle 2015/08/19 22:41:35 Instead of using these progress vectors and compar
amohammadkhan 2015/08/20 00:20:13 By comparing these values I am showing the progres
683 std::vector<base::Bucket> samples;
684 EXPECT_TRUE(SyncShareNudge());
685 {
686 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 0);
687 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 0);
688 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1);
689 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Count",
690 BOOKMARKS, 1);
691 samples = histogram_tester.GetAllSamples("DataUse.Sync.Download.Bytes");
692 EXPECT_TRUE(samples.size() == 1);
Nicolas Zea 2015/08/19 22:01:51 nit: use EXPECT_EQ, EXPECT_GE, EXPECT_GT where pos
amohammadkhan 2015/08/20 00:20:13 Done.
693 EXPECT_TRUE(samples.at(0).min == BOOKMARKS);
694 EXPECT_TRUE(samples.at(0).count >= 0);
695 download_bytes_bookmark = samples.at(0).count;
696
697 samples = histogram_tester.GetAllSamples(
698 "DataUse.Sync.ProgressMarker.Bytes");
699
700 for(std::vector<base::Bucket>::iterator it = samples.begin();
sclittle 2015/08/19 22:41:35 nit: use range-based for, e.g. for (const base::Bu
amohammadkhan 2015/08/20 00:20:13 Done.
701 it != samples.end(); ++it) {
702 if (it->min == BOOKMARKS)
703 progress_bookmark.at(0) += it->count;
Nicolas Zea 2015/08/19 22:01:51 there should only be one bucket with value BOOKMAR
amohammadkhan 2015/08/20 00:20:13 Yes it should be one here. But I was thinking mayb
704 progress_all.at(0) += it->count;
705 }
706 EXPECT_TRUE(progress_bookmark.at(0) > 0);
707 EXPECT_TRUE(progress_all.at(0) > 0);
Nicolas Zea 2015/08/19 22:01:51 should progress_all == progress_bookmark? Maybe th
amohammadkhan 2015/08/20 00:20:13 They are not equal because of having progress mark
708
709 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
710 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
711 A.PutIsUnsynced(true);
712 A.PutSpecifics(bookmark_data);
713 A.PutNonUniqueName("bookmark");
714 }
715
716 // Now sync without enabling bookmarks.
717 mock_server_->ExpectGetUpdatesRequestTypes(
718 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)));
719 ResetSession();
720 syncer_->NormalSyncShare(
721 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)),
722 &nudge_tracker_, session_.get());
723
724 {
725 // Nothing should have been committed as bookmarks is throttled.
726 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 0);
727 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 0);
728 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1);
729 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Count",
730 BOOKMARKS, 1);
731
732 samples = histogram_tester.GetAllSamples("DataUse.Sync.Download.Bytes");
733 EXPECT_TRUE(samples.size() == 1);
734 EXPECT_TRUE(samples.at(0).min == BOOKMARKS);
735 EXPECT_TRUE(samples.at(0).count == download_bytes_bookmark);
736
737 samples = histogram_tester.GetAllSamples(
738 "DataUse.Sync.ProgressMarker.Bytes");
739 for(std::vector<base::Bucket>::iterator it = samples.begin();
740 it != samples.end(); ++it) {
741 if (it->min == BOOKMARKS)
742 progress_bookmark.at(1) += it->count;
743 progress_all.at(1) += it->count;
744 }
745 EXPECT_TRUE(progress_bookmark.at(1) == progress_bookmark.at(0));
746 EXPECT_TRUE(progress_all.at(1) > progress_all.at(0));
747 }
748
749 // Sync again with bookmarks enabled.
750 mock_server_->ExpectGetUpdatesRequestTypes(context_->GetEnabledTypes());
751 EXPECT_TRUE(SyncShareNudge());
752 {
753 // It should have been committed.
754 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 1);
755 histogram_tester.ExpectUniqueSample("DataUse.Sync.Upload.Count",
756 BOOKMARKS,1);
757 samples = histogram_tester.GetAllSamples("DataUse.Sync.Upload.Bytes");
758 EXPECT_TRUE(samples.size() == 1);
759 EXPECT_TRUE(samples.at(0).min == BOOKMARKS);
760 EXPECT_TRUE(samples.at(0).count >= 0);
761
762 samples = histogram_tester.GetAllSamples("DataUse.Sync.Download.Bytes");
763 EXPECT_TRUE(samples.size() == 1);
764 EXPECT_TRUE(samples.at(0).min == BOOKMARKS);
765 EXPECT_TRUE(samples.at(0).count == download_bytes_bookmark);
766
767 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1);
768
769 samples = histogram_tester.GetAllSamples(
770 "DataUse.Sync.ProgressMarker.Bytes");
771 for(std::vector<base::Bucket>::iterator it = samples.begin();
772 it != samples.end(); ++it) {
773 if (it->min == BOOKMARKS)
774 progress_bookmark.at(2) += it->count;
775 progress_all.at(2) += it->count;
776 }
777 EXPECT_TRUE(progress_bookmark.at(2) > progress_bookmark.at(1));
778 EXPECT_TRUE(progress_all.at(2) > progress_all.at(1));
779 }
780 }
781
669 // We use a macro so we can preserve the error location. 782 // We use a macro so we can preserve the error location.
670 #define VERIFY_ENTRY(id, is_unapplied, is_unsynced, prev_initialized, \ 783 #define VERIFY_ENTRY(id, is_unapplied, is_unsynced, prev_initialized, \
671 parent_id, version, server_version, id_fac, rtrans) \ 784 parent_id, version, server_version, id_fac, rtrans) \
672 do { \ 785 do { \
673 Entry entryA(rtrans, syncable::GET_BY_ID, id_fac.FromNumber(id)); \ 786 Entry entryA(rtrans, syncable::GET_BY_ID, id_fac.FromNumber(id)); \
674 ASSERT_TRUE(entryA.good()); \ 787 ASSERT_TRUE(entryA.good()); \
675 /* We don't use EXPECT_EQ here because when the left side param is false, 788 /* We don't use EXPECT_EQ here because when the left side param is false,
676 gcc 4.6 warns about converting 'false' to pointer type for argument 1. */ \ 789 gcc 4.6 warns about converting 'false' to pointer type for argument 1. */ \
677 EXPECT_TRUE(is_unsynced == entryA.GetIsUnsynced()); \ 790 EXPECT_TRUE(is_unsynced == entryA.GetIsUnsynced()); \
678 EXPECT_TRUE(is_unapplied == entryA.GetIsUnappliedUpdate()); \ 791 EXPECT_TRUE(is_unapplied == entryA.GetIsUnappliedUpdate()); \
(...skipping 4808 matching lines...) Expand 10 before | Expand all | Expand 10 after
5487 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); 5600 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
5488 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 5601 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
5489 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 5602 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
5490 } else { 5603 } else {
5491 EXPECT_TRUE(final_monitor_records.empty()) 5604 EXPECT_TRUE(final_monitor_records.empty())
5492 << "Should not restore records after successful bookmark commit."; 5605 << "Should not restore records after successful bookmark commit.";
5493 } 5606 }
5494 } 5607 }
5495 5608
5496 } // namespace syncer 5609 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698