Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2011 Google Inc. All Rights Reserved. | |
| 2 // Author: braffert@google.com (Ben Rafferty) | |
|
Raghu Simha
2011/06/15 18:38:16
Use the standard chromium header. See any other fi
braffert
2011/06/16 00:59:24
Done.
| |
| 3 | |
| 4 #include "base/time.h" | |
| 5 #include "chrome/browser/profiles/profile.h" | |
| 6 #include "chrome/browser/sync/profile_sync_service_harness.h" | |
| 7 #include "chrome/test/live_sync/live_bookmarks_sync_test.h" | |
| 8 | |
| 9 static const int kNumBookmarks = 150; | |
| 10 | |
| 11 // TODO(braffert): Consider the range / resolution of these test points. | |
|
Raghu Simha
2011/06/15 18:38:16
How long does it take to run through all points on
braffert
2011/06/16 00:59:24
I can't say for sure - It depends on whether the P
Raghu Simha
2011/06/16 22:42:54
SGTM.
| |
| 12 static const int kNumBenchmarkPoints = 18; | |
| 13 static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, | |
| 14 150, 175, 200, 225, 250, 300, 350, 400, | |
| 15 500}; | |
| 16 | |
| 17 // TODO(braffert): Move this class into its own .h/.cc files. Maybe. | |
|
Raghu Simha
2011/06/15 18:38:16
s/Maybe/Yes/ :)
It's much cleaner, and will allow
braffert
2011/06/16 00:59:24
I've split up the declaration and definition here
| |
| 18 class PerformanceLiveBookmarksSyncTest | |
| 19 : public TwoClientLiveBookmarksSyncTest { | |
| 20 public: | |
| 21 PerformanceLiveBookmarksSyncTest() : urlNumber(0), urlTitleNumber(0) {} | |
| 22 | |
| 23 void AddURLs(int profile, int nURLs) { | |
| 24 for (int i = 0; i < nURLs; ++i) { | |
| 25 ASSERT_TRUE(AddURL( | |
| 26 profile, 0, NextIndexedURLTitle(), NextIndexedURL()) != NULL); | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 void UpdateURLs(int profile) { | |
| 31 for (int i = 0; i < GetBookmarkBarNode(profile)->child_count(); ++i) { | |
| 32 ASSERT_TRUE(SetURL(profile, GetBookmarkBarNode(profile)->GetChild(i), | |
| 33 NextIndexedURL())); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 void RemoveURLs(int profile) { | |
| 38 while (GetBookmarkBarNode(profile)->child_count()) { | |
| 39 Remove(profile, GetBookmarkBarNode(profile), 0); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 void Cleanup() { | |
|
Raghu Simha
2011/06/15 18:38:16
I'm wondering if this method is really necessary,
braffert
2011/06/16 00:59:24
Cleanup() is called between benchmark iterations t
Raghu Simha
2011/06/16 22:42:54
SGTM.
| |
| 44 for (int i = 0; i < num_clients(); ++i) { | |
| 45 RemoveURLs(i); | |
| 46 } | |
| 47 ASSERT_TRUE(AwaitQuiescence()); | |
| 48 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | |
| 49 ASSERT_TRUE(AllModelsMatch()); | |
| 50 } | |
| 51 | |
| 52 // TODO(braffert): Move timing methods somewhere that they can be used by | |
| 53 // the performance test class for all datatypes. | |
|
Raghu Simha
2011/06/15 18:38:16
To be able to use these across datatypes, how abou
braffert
2011/06/16 00:59:24
Done. This required overriding the SetUp method o
Raghu Simha
2011/06/16 22:42:54
In other comments, I've suggested some changes to
| |
| 54 base::TimeDelta TimeSyncCycle(ProfileSyncServiceHarness* client) { | |
| 55 base::Time start = base::Time::Now(); | |
| 56 EXPECT_TRUE(client->AwaitSyncCycleCompletion("Timing sync cycle.")); | |
| 57 return base::Time::Now() - start; | |
| 58 } | |
| 59 | |
| 60 base::TimeDelta TimeMutualSyncCycle(ProfileSyncServiceHarness* client, | |
| 61 ProfileSyncServiceHarness* partner) { | |
| 62 base::Time start = base::Time::Now(); | |
| 63 EXPECT_TRUE(client->AwaitMutualSyncCycleCompletion(partner)); | |
| 64 return base::Time::Now() - start; | |
| 65 } | |
| 66 | |
| 67 base::TimeDelta TimeUntilQuiescence() { | |
| 68 base::Time start = base::Time::Now(); | |
| 69 EXPECT_TRUE(AwaitQuiescence()); | |
| 70 return base::Time::Now() - start; | |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 GURL NextIndexedURL() { | |
| 75 return GURL(IndexedURL(urlNumber++)); | |
| 76 } | |
| 77 | |
| 78 std::wstring NextIndexedURLTitle() { | |
| 79 return IndexedURLTitle(urlTitleNumber++); | |
| 80 } | |
| 81 | |
| 82 int urlNumber; | |
| 83 int urlTitleNumber; | |
| 84 DISALLOW_COPY_AND_ASSIGN(PerformanceLiveBookmarksSyncTest); | |
| 85 }; | |
| 86 | |
| 87 // TODO(braffert): Possibly split each of these into separate up / down test | |
| 88 // cases? | |
| 89 IN_PROC_BROWSER_TEST_F(PerformanceLiveBookmarksSyncTest, Add) { | |
| 90 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 91 DisableVerifier(); | |
| 92 | |
| 93 DisableNetwork(GetProfile(1)); | |
| 94 AddURLs(0, kNumBookmarks); | |
| 95 base::TimeDelta dt_up = TimeSyncCycle(GetClient(0)); | |
| 96 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); | |
| 97 ASSERT_EQ(0, GetBookmarkBarNode(1)->child_count()); | |
| 98 | |
| 99 EnableNetwork(GetProfile(1)); | |
| 100 base::TimeDelta dt_down = TimeUntilQuiescence(); | |
|
Raghu Simha
2011/06/15 18:38:16
TimeUntilQuiescence(1) will include any sync cycle
braffert
2011/06/16 00:59:24
Calling TimeSyncCycle(1) instead of AwaitQuiescenc
| |
| 101 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); | |
| 102 ASSERT_TRUE(AllModelsMatch()); | |
| 103 | |
| 104 // TODO(braffert): Compare timings against some target value. | |
| 105 } | |
| 106 | |
| 107 IN_PROC_BROWSER_TEST_F(PerformanceLiveBookmarksSyncTest, Update) { | |
| 108 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 109 DisableVerifier(); | |
| 110 | |
| 111 AddURLs(0, kNumBookmarks); | |
| 112 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 113 ASSERT_TRUE(AllModelsMatch()); | |
| 114 | |
| 115 DisableNetwork(GetProfile(1)); | |
| 116 UpdateURLs(0); | |
| 117 base::TimeDelta dt_up = TimeSyncCycle(GetClient(0)); | |
| 118 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); | |
| 119 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(1)->child_count()); | |
| 120 ASSERT_FALSE(AllModelsMatch()); | |
| 121 | |
| 122 EnableNetwork(GetProfile(1)); | |
| 123 base::TimeDelta dt_down = TimeUntilQuiescence(); | |
| 124 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(0)->child_count()); | |
| 125 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(1)->child_count()); | |
| 126 | |
| 127 // TODO(braffert): Compare timings against some target value. | |
| 128 } | |
| 129 | |
| 130 IN_PROC_BROWSER_TEST_F(PerformanceLiveBookmarksSyncTest, Delete) { | |
| 131 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 132 DisableVerifier(); | |
| 133 | |
| 134 AddURLs(0, kNumBookmarks); | |
| 135 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 136 ASSERT_TRUE(AllModelsMatch()); | |
| 137 | |
| 138 DisableNetwork(GetProfile(1)); | |
| 139 RemoveURLs(0); | |
| 140 base::TimeDelta dt_up = TimeSyncCycle(GetClient(0)); | |
| 141 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | |
| 142 ASSERT_EQ(kNumBookmarks, GetBookmarkBarNode(1)->child_count()); | |
| 143 | |
| 144 EnableNetwork(GetProfile(1)); | |
| 145 base::TimeDelta dt_down = TimeUntilQuiescence(); | |
| 146 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | |
| 147 ASSERT_EQ(0, GetBookmarkBarNode(1)->child_count()); | |
| 148 | |
| 149 // TODO(braffert): Compare timings against some target value. | |
| 150 } | |
| 151 | |
| 152 IN_PROC_BROWSER_TEST_F(PerformanceLiveBookmarksSyncTest, Benchmark) { | |
| 153 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 154 DisableVerifier(); | |
| 155 | |
| 156 for (int i = 0; i < kNumBenchmarkPoints; ++i) { | |
| 157 int numBookmarks = kBenchmarkPoints[i]; | |
| 158 | |
| 159 // Disable client 1. Add bookmarks and time commit by client 0. | |
| 160 DisableNetwork(GetProfile(1)); | |
| 161 AddURLs(0, numBookmarks); | |
| 162 base::TimeDelta dt_up = TimeSyncCycle(GetClient(0)); | |
| 163 ASSERT_EQ(numBookmarks, GetBookmarkBarNode(0)->child_count()); | |
| 164 ASSERT_EQ(0, GetBookmarkBarNode(1)->child_count()); | |
| 165 | |
| 166 // Enable client 1 and time update (new bookmarks). | |
| 167 EnableNetwork(GetProfile(1)); | |
| 168 base::TimeDelta dt_down = TimeUntilQuiescence(); | |
| 169 ASSERT_EQ(numBookmarks, GetBookmarkBarNode(0)->child_count()); | |
| 170 ASSERT_TRUE(AllModelsMatch()); | |
| 171 | |
| 172 VLOG(0) << "Add: " << numBookmarks << " " << | |
| 173 static_cast<double>(numBookmarks) / dt_up.InSecondsF() << " " << | |
| 174 static_cast<double>(numBookmarks) / dt_down.InSecondsF(); | |
| 175 | |
| 176 // Disable client 1. Modify bookmarks and time commit by client 0. | |
| 177 DisableNetwork(GetProfile(1)); | |
| 178 UpdateURLs(0); | |
| 179 dt_up = TimeSyncCycle(GetClient(0)); | |
| 180 ASSERT_EQ(numBookmarks, GetBookmarkBarNode(0)->child_count()); | |
| 181 ASSERT_EQ(numBookmarks, GetBookmarkBarNode(1)->child_count()); | |
| 182 ASSERT_FALSE(AllModelsMatch()); | |
| 183 | |
| 184 // Enable client 1 and time update (changed bookmarks). | |
| 185 EnableNetwork(GetProfile(1)); | |
| 186 dt_down = TimeUntilQuiescence(); | |
| 187 ASSERT_EQ(numBookmarks, GetBookmarkBarNode(0)->child_count()); | |
| 188 ASSERT_TRUE(AllModelsMatch()); | |
| 189 | |
| 190 VLOG(0) << "Update: " << numBookmarks << " " << | |
| 191 static_cast<double>(numBookmarks) / dt_up.InSecondsF() << " " << | |
| 192 static_cast<double>(numBookmarks) / dt_down.InSecondsF(); | |
| 193 | |
| 194 // Disable client 1. Delete bookmarks and time commit by client 0. | |
| 195 DisableNetwork(GetProfile(1)); | |
| 196 RemoveURLs(0); | |
| 197 dt_up = TimeSyncCycle(GetClient(0)); | |
| 198 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | |
| 199 ASSERT_EQ(numBookmarks, GetBookmarkBarNode(1)->child_count()); | |
| 200 | |
| 201 // Enable client 1 and time update (deleted bookmarks). | |
| 202 EnableNetwork(GetProfile(1)); | |
| 203 dt_down = TimeUntilQuiescence(); | |
| 204 ASSERT_EQ(0, GetBookmarkBarNode(0)->child_count()); | |
| 205 ASSERT_EQ(0, GetBookmarkBarNode(1)->child_count()); | |
| 206 | |
| 207 VLOG(0) << "Delete: " << numBookmarks << " " << | |
| 208 static_cast<double>(numBookmarks) / dt_up.InSecondsF() << " " << | |
| 209 static_cast<double>(numBookmarks) / dt_down.InSecondsF(); | |
| 210 | |
| 211 Cleanup(); | |
| 212 } | |
| 213 } | |
| 214 | |
| OLD | NEW |