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

Side by Side Diff: net/nqe/observation_buffer_unittest.cc

Issue 2453653002: Separate out observation sources as either HTTP layer or transport layer (Closed)
Patch Set: ps Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "net/nqe/observation_buffer.h" 5 #include "net/nqe/observation_buffer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 15 matching lines...) Expand all
26 namespace internal { 26 namespace internal {
27 27
28 namespace { 28 namespace {
29 29
30 // Verify that the buffer size is never exceeded. 30 // Verify that the buffer size is never exceeded.
31 TEST(NetworkQualityObservationBufferTest, BoundedBuffer) { 31 TEST(NetworkQualityObservationBufferTest, BoundedBuffer) {
32 ObservationBuffer<int32_t> observation_buffer(1.0); 32 ObservationBuffer<int32_t> observation_buffer(1.0);
33 const base::TimeTicks now = 33 const base::TimeTicks now =
34 base::TimeTicks() + base::TimeDelta::FromSeconds(1); 34 base::TimeTicks() + base::TimeDelta::FromSeconds(1);
35 for (int i = 1; i <= 1000; ++i) { 35 for (int i = 1; i <= 1000; ++i) {
36 observation_buffer.AddObservation( 36 observation_buffer.AddObservation(Observation<int32_t>(
37 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); 37 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT));
38 // The number of entries should be at most the maximum buffer size. 38 // The number of entries should be at most the maximum buffer size.
39 EXPECT_GE(300u, observation_buffer.Size()); 39 EXPECT_GE(300u, observation_buffer.Size());
40 } 40 }
41 } 41 }
42 42
43 // Test disabled on OS_WIN to avoid linking errors when calling 43 // Test disabled on OS_WIN to avoid linking errors when calling
44 // SetTickClockForTesting. 44 // SetTickClockForTesting.
45 // TODO(tbansal): crbug.com/651963. Pass the clock through NQE's constructor. 45 // TODO(tbansal): crbug.com/651963. Pass the clock through NQE's constructor.
46 #if !defined(OS_WIN) 46 #if !defined(OS_WIN)
47 // Verify that the percentiles are monotonically non-decreasing when a weight is 47 // Verify that the percentiles are monotonically non-decreasing when a weight is
48 // applied. 48 // applied.
49 TEST(NetworkQualityObservationBufferTest, GetPercentileWithWeights) { 49 TEST(NetworkQualityObservationBufferTest, GetPercentileWithWeights) {
50 std::unique_ptr<base::SimpleTestTickClock> tick_clock( 50 std::unique_ptr<base::SimpleTestTickClock> tick_clock(
51 new base::SimpleTestTickClock()); 51 new base::SimpleTestTickClock());
52 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); 52 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get();
53 53
54 ObservationBuffer<int32_t> observation_buffer(0.98); 54 ObservationBuffer<int32_t> observation_buffer(0.98);
55 observation_buffer.SetTickClockForTesting(std::move(tick_clock)); 55 observation_buffer.SetTickClockForTesting(std::move(tick_clock));
56 const base::TimeTicks now = tick_clock_ptr->NowTicks(); 56 const base::TimeTicks now = tick_clock_ptr->NowTicks();
57 for (int i = 1; i <= 100; ++i) { 57 for (int i = 1; i <= 100; ++i) {
58 tick_clock_ptr->Advance(base::TimeDelta::FromSeconds(1)); 58 tick_clock_ptr->Advance(base::TimeDelta::FromSeconds(1));
59 observation_buffer.AddObservation(Observation<int32_t>( 59 observation_buffer.AddObservation(
60 i, tick_clock_ptr->NowTicks(), NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); 60 Observation<int32_t>(i, tick_clock_ptr->NowTicks(),
61 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT));
61 } 62 }
62 EXPECT_EQ(100U, observation_buffer.Size()); 63 EXPECT_EQ(100U, observation_buffer.Size());
63 64
64 int32_t result_lowest = INT32_MAX; 65 int32_t result_lowest = INT32_MAX;
65 int32_t result_highest = INT32_MIN; 66 int32_t result_highest = INT32_MIN;
66 67
67 for (int i = 1; i <= 100; ++i) { 68 for (int i = 1; i <= 100; ++i) {
68 // Verify that i'th percentile is more than i-1'th percentile. 69 // Verify that i'th percentile is more than i-1'th percentile.
69 int32_t result_i; 70 int32_t result_i;
70 EXPECT_TRUE(observation_buffer.GetPercentile( 71 EXPECT_TRUE(observation_buffer.GetPercentile(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 EXPECT_FALSE( 104 EXPECT_FALSE(
104 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, 105 int_buffer.GetPercentile(base::TimeTicks(), &result, 50,
105 std::vector<NetworkQualityObservationSource>())); 106 std::vector<NetworkQualityObservationSource>()));
106 EXPECT_FALSE(time_delta_buffer.GetPercentile( 107 EXPECT_FALSE(time_delta_buffer.GetPercentile(
107 base::TimeTicks(), &time_delta_result, 50, 108 base::TimeTicks(), &time_delta_result, 50,
108 std::vector<NetworkQualityObservationSource>())); 109 std::vector<NetworkQualityObservationSource>()));
109 110
110 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even 111 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even
111 // samples. This helps in verifying that the order of samples does not matter. 112 // samples. This helps in verifying that the order of samples does not matter.
112 for (int i = 1; i <= 99; i += 2) { 113 for (int i = 1; i <= 99; i += 2) {
113 int_buffer.AddObservation(Observation<int32_t>( 114 int_buffer.AddObservation(
114 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 115 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
115 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 116 time_delta_buffer.AddObservation(
116 base::TimeDelta::FromMilliseconds(i), now, 117 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
117 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 118 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
118 EXPECT_TRUE(int_buffer.GetPercentile( 119 EXPECT_TRUE(int_buffer.GetPercentile(
119 base::TimeTicks(), &result, 50, 120 base::TimeTicks(), &result, 50,
120 std::vector<NetworkQualityObservationSource>())); 121 std::vector<NetworkQualityObservationSource>()));
121 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), int_buffer.Size()); 122 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), int_buffer.Size());
122 EXPECT_TRUE(time_delta_buffer.GetPercentile( 123 EXPECT_TRUE(time_delta_buffer.GetPercentile(
123 base::TimeTicks(), &time_delta_result, 50, 124 base::TimeTicks(), &time_delta_result, 50,
124 std::vector<NetworkQualityObservationSource>())); 125 std::vector<NetworkQualityObservationSource>()));
125 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), time_delta_buffer.Size()); 126 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), time_delta_buffer.Size());
126 } 127 }
127 128
128 for (int i = 2; i <= 100; i += 2) { 129 for (int i = 2; i <= 100; i += 2) {
129 int_buffer.AddObservation(Observation<int32_t>( 130 int_buffer.AddObservation(
130 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 131 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
131 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 132 time_delta_buffer.AddObservation(
132 base::TimeDelta::FromMilliseconds(i), now, 133 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
133 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 134 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
134 EXPECT_TRUE(int_buffer.GetPercentile( 135 EXPECT_TRUE(int_buffer.GetPercentile(
135 base::TimeTicks(), &result, 50, 136 base::TimeTicks(), &result, 50,
136 std::vector<NetworkQualityObservationSource>())); 137 std::vector<NetworkQualityObservationSource>()));
137 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), int_buffer.Size()); 138 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), int_buffer.Size());
138 EXPECT_TRUE(time_delta_buffer.GetPercentile( 139 EXPECT_TRUE(time_delta_buffer.GetPercentile(
139 base::TimeTicks(), &time_delta_result, 50, 140 base::TimeTicks(), &time_delta_result, 50,
140 std::vector<NetworkQualityObservationSource>())); 141 std::vector<NetworkQualityObservationSource>()));
141 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), time_delta_buffer.Size()); 142 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), time_delta_buffer.Size());
142 } 143 }
143 144
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 EXPECT_FALSE( 195 EXPECT_FALSE(
195 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, 196 int_buffer.GetPercentile(base::TimeTicks(), &result, 50,
196 std::vector<NetworkQualityObservationSource>())); 197 std::vector<NetworkQualityObservationSource>()));
197 EXPECT_FALSE(time_delta_buffer.GetPercentile( 198 EXPECT_FALSE(time_delta_buffer.GetPercentile(
198 base::TimeTicks(), &time_delta_result, 50, 199 base::TimeTicks(), &time_delta_result, 50,
199 std::vector<NetworkQualityObservationSource>())); 200 std::vector<NetworkQualityObservationSource>()));
200 201
201 // First 50 samples have very old timestamps. 202 // First 50 samples have very old timestamps.
202 for (int i = 1; i <= 50; ++i) { 203 for (int i = 1; i <= 50; ++i) {
203 int_buffer.AddObservation(Observation<int32_t>( 204 int_buffer.AddObservation(Observation<int32_t>(
204 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 205 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
205 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 206 time_delta_buffer.AddObservation(Observation<base::TimeDelta>(
206 base::TimeDelta::FromMilliseconds(i), very_old, 207 base::TimeDelta::FromMilliseconds(i), very_old,
207 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 208 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
208 } 209 }
209 210
210 // Next 50 (i.e., from 51 to 100) have recent timestamps. 211 // Next 50 (i.e., from 51 to 100) have recent timestamps.
211 for (int i = 51; i <= 100; ++i) { 212 for (int i = 51; i <= 100; ++i) {
212 int_buffer.AddObservation(Observation<int32_t>( 213 int_buffer.AddObservation(
213 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 214 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
214 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 215 time_delta_buffer.AddObservation(
215 base::TimeDelta::FromMilliseconds(i), now, 216 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
216 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 217 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
217 } 218 }
218 219
219 // Older samples have very little weight. So, all percentiles are >= 51 220 // Older samples have very little weight. So, all percentiles are >= 51
220 // (lowest value among recent observations). 221 // (lowest value among recent observations).
221 for (int i = 1; i < 100; ++i) { 222 for (int i = 1; i < 100; ++i) {
222 // Checks if the difference between the two integers is less than 1. This is 223 // Checks if the difference between the two integers is less than 1. This is
223 // required because computed percentiles may be slightly different from 224 // required because computed percentiles may be slightly different from
224 // what is expected due to floating point computation errors and integer 225 // what is expected due to floating point computation errors and integer
225 // rounding off errors. 226 // rounding off errors.
226 EXPECT_TRUE(int_buffer.GetPercentile( 227 EXPECT_TRUE(int_buffer.GetPercentile(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(), 263 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(),
263 &time_delta_result)); 264 &time_delta_result));
264 EXPECT_FALSE(int_buffer.GetUnweightedAverage( 265 EXPECT_FALSE(int_buffer.GetUnweightedAverage(
265 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(), 266 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(),
266 &int_result)); 267 &int_result));
267 268
268 // The first 50 samples have very old timestamps. 269 // The first 50 samples have very old timestamps.
269 for (int i = 1; i <= 50; ++i) { 270 for (int i = 1; i <= 50; ++i) {
270 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 271 time_delta_buffer.AddObservation(Observation<base::TimeDelta>(
271 base::TimeDelta::FromMilliseconds(i), very_old, 272 base::TimeDelta::FromMilliseconds(i), very_old,
272 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 273 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
273 int_buffer.AddObservation(Observation<int32_t>( 274 int_buffer.AddObservation(Observation<int32_t>(
274 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 275 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
275 } 276 }
276 277
277 // The next 50 (i.e., from 51 to 100) samples have recent timestamps. 278 // The next 50 (i.e., from 51 to 100) samples have recent timestamps.
278 for (int i = 51; i <= 100; ++i) { 279 for (int i = 51; i <= 100; ++i) {
279 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 280 time_delta_buffer.AddObservation(
280 base::TimeDelta::FromMilliseconds(i), now, 281 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
281 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 282 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
282 int_buffer.AddObservation(Observation<int32_t>( 283 int_buffer.AddObservation(
283 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 284 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
284 } 285 }
285 286
286 // All samples have equal weight. So, the unweighted average is the average of 287 // All samples have equal weight. So, the unweighted average is the average of
287 // all samples. 288 // all samples.
288 EXPECT_TRUE(time_delta_buffer.GetUnweightedAverage( 289 EXPECT_TRUE(time_delta_buffer.GetUnweightedAverage(
289 very_old, std::vector<NetworkQualityObservationSource>(), 290 very_old, std::vector<NetworkQualityObservationSource>(),
290 &time_delta_result)); 291 &time_delta_result));
291 EXPECT_NEAR(time_delta_result.InMilliseconds(), (1 + 100) / 2, 1); 292 EXPECT_NEAR(time_delta_result.InMilliseconds(), (1 + 100) / 2, 1);
292 293
293 EXPECT_TRUE(int_buffer.GetUnweightedAverage( 294 EXPECT_TRUE(int_buffer.GetUnweightedAverage(
(...skipping 22 matching lines...) Expand all
316 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(), 317 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(),
317 &time_delta_result)); 318 &time_delta_result));
318 EXPECT_FALSE(int_buffer.GetWeightedAverage( 319 EXPECT_FALSE(int_buffer.GetWeightedAverage(
319 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(), 320 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(),
320 &int_result)); 321 &int_result));
321 322
322 // The first 50 samples have very old timestamps. 323 // The first 50 samples have very old timestamps.
323 for (int i = 1; i <= 50; ++i) { 324 for (int i = 1; i <= 50; ++i) {
324 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 325 time_delta_buffer.AddObservation(Observation<base::TimeDelta>(
325 base::TimeDelta::FromMilliseconds(i), very_old, 326 base::TimeDelta::FromMilliseconds(i), very_old,
326 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 327 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
327 int_buffer.AddObservation(Observation<int32_t>( 328 int_buffer.AddObservation(Observation<int32_t>(
328 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 329 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
329 } 330 }
330 331
331 // The next 50 (i.e., from 51 to 100) samples have recent timestamps. 332 // The next 50 (i.e., from 51 to 100) samples have recent timestamps.
332 for (int i = 51; i <= 100; ++i) { 333 for (int i = 51; i <= 100; ++i) {
333 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 334 time_delta_buffer.AddObservation(
334 base::TimeDelta::FromMilliseconds(i), now, 335 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
335 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 336 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
336 int_buffer.AddObservation(Observation<int32_t>( 337 int_buffer.AddObservation(
337 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 338 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
338 } 339 }
339 340
340 // The older samples have very little weight, and so the weighted average must 341 // The older samples have very little weight, and so the weighted average must
341 // be approximately equal to the average of all recent samples. 342 // be approximately equal to the average of all recent samples.
342 EXPECT_TRUE(time_delta_buffer.GetWeightedAverage( 343 EXPECT_TRUE(time_delta_buffer.GetWeightedAverage(
343 very_old, std::vector<NetworkQualityObservationSource>(), 344 very_old, std::vector<NetworkQualityObservationSource>(),
344 &time_delta_result)); 345 &time_delta_result));
345 EXPECT_NEAR(time_delta_result.InMilliseconds(), (51 + 100) / 2, 1); 346 EXPECT_NEAR(time_delta_result.InMilliseconds(), (51 + 100) / 2, 1);
346 347
347 EXPECT_TRUE(int_buffer.GetWeightedAverage( 348 EXPECT_TRUE(int_buffer.GetWeightedAverage(
(...skipping 23 matching lines...) Expand all
371 EXPECT_FALSE( 372 EXPECT_FALSE(
372 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, 373 int_buffer.GetPercentile(base::TimeTicks(), &result, 50,
373 std::vector<NetworkQualityObservationSource>())); 374 std::vector<NetworkQualityObservationSource>()));
374 EXPECT_FALSE(time_delta_buffer.GetPercentile( 375 EXPECT_FALSE(time_delta_buffer.GetPercentile(
375 base::TimeTicks(), &time_delta_result, 50, 376 base::TimeTicks(), &time_delta_result, 50,
376 std::vector<NetworkQualityObservationSource>())); 377 std::vector<NetworkQualityObservationSource>()));
377 378
378 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even 379 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even
379 // samples. This helps in verifying that the order of samples does not matter. 380 // samples. This helps in verifying that the order of samples does not matter.
380 for (int i = 1; i <= 99; i += 2) { 381 for (int i = 1; i <= 99; i += 2) {
381 int_buffer.AddObservation(Observation<int32_t>( 382 int_buffer.AddObservation(
382 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 383 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
383 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 384 time_delta_buffer.AddObservation(
384 base::TimeDelta::FromMilliseconds(i), now, 385 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
385 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 386 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
386 } 387 }
387 388
388 // Add samples for TCP and QUIC observations which should not be taken into 389 // Add samples for TCP and QUIC observations which should not be taken into
389 // account when computing the percentile. 390 // account when computing the percentile.
390 for (int i = 1; i <= 99; i += 2) { 391 for (int i = 1; i <= 99; i += 2) {
391 int_buffer.AddObservation(Observation<int32_t>( 392 int_buffer.AddObservation(Observation<int32_t>(
392 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); 393 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT));
393 int_buffer.AddObservation(Observation<int32_t>( 394 int_buffer.AddObservation(Observation<int32_t>(
394 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC)); 395 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT));
395 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 396 time_delta_buffer.AddObservation(Observation<base::TimeDelta>(
396 base::TimeDelta::FromMilliseconds(10000), now, 397 base::TimeDelta::FromMilliseconds(10000), now,
397 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); 398 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT));
398 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 399 time_delta_buffer.AddObservation(Observation<base::TimeDelta>(
399 base::TimeDelta::FromMilliseconds(10000), now, 400 base::TimeDelta::FromMilliseconds(10000), now,
400 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC)); 401 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT));
401 } 402 }
402 403
403 for (int i = 2; i <= 100; i += 2) { 404 for (int i = 2; i <= 100; i += 2) {
404 int_buffer.AddObservation(Observation<int32_t>( 405 int_buffer.AddObservation(
405 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 406 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
406 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 407 time_delta_buffer.AddObservation(
407 base::TimeDelta::FromMilliseconds(i), now, 408 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
408 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 409 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
409 } 410 }
410 411
411 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; 412 std::vector<NetworkQualityObservationSource> disallowed_observation_sources;
412 disallowed_observation_sources.push_back( 413 disallowed_observation_sources.push_back(
413 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); 414 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT);
414 disallowed_observation_sources.push_back(
415 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC);
416 415
417 for (int i = 0; i <= 100; ++i) { 416 for (int i = 0; i <= 100; ++i) {
418 // Checks if the difference between the two integers is less than 1. This is 417 // Checks if the difference between the two integers is less than 1. This is
419 // required because computed percentiles may be slightly different from 418 // required because computed percentiles may be slightly different from
420 // what is expected due to floating point computation errors and integer 419 // what is expected due to floating point computation errors and integer
421 // rounding off errors. 420 // rounding off errors.
422 EXPECT_TRUE(int_buffer.GetPercentile(base::TimeTicks(), &result, i, 421 EXPECT_TRUE(int_buffer.GetPercentile(base::TimeTicks(), &result, i,
423 disallowed_observation_sources)); 422 disallowed_observation_sources));
424 EXPECT_NEAR(result, i, 1); 423 EXPECT_NEAR(result, i, 1);
425 EXPECT_TRUE( 424 EXPECT_TRUE(
426 time_delta_buffer.GetPercentile(base::TimeTicks(), &time_delta_result, 425 time_delta_buffer.GetPercentile(base::TimeTicks(), &time_delta_result,
427 i, disallowed_observation_sources)); 426 i, disallowed_observation_sources));
428 EXPECT_NEAR(time_delta_result.InMilliseconds(), i, 1); 427 EXPECT_NEAR(time_delta_result.InMilliseconds(), i, 1);
429 } 428 }
430 429
431 // Now check the percentile value for TCP and QUIC observations. 430 // Now check the percentile value for TCP and QUIC observations.
432 disallowed_observation_sources.clear(); 431 disallowed_observation_sources.clear();
433 disallowed_observation_sources.push_back( 432 disallowed_observation_sources.push_back(
434 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); 433 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP);
435 for (int i = 0; i <= 100; ++i) { 434 for (int i = 0; i <= 100; ++i) {
436 // Checks if the difference between the two integers is less than 1. This is 435 // Checks if the difference between the two integers is less than 1. This is
437 // required because computed percentiles may be slightly different from 436 // required because computed percentiles may be slightly different from
438 // what is expected due to floating point computation errors and integer 437 // what is expected due to floating point computation errors and integer
439 // rounding off errors. 438 // rounding off errors.
440 EXPECT_TRUE(int_buffer.GetPercentile(base::TimeTicks(), &result, i, 439 EXPECT_TRUE(int_buffer.GetPercentile(base::TimeTicks(), &result, i,
441 disallowed_observation_sources)); 440 disallowed_observation_sources));
442 EXPECT_NEAR(result, 10000, 1); 441 EXPECT_NEAR(result, 10000, 1);
443 EXPECT_TRUE( 442 EXPECT_TRUE(
444 time_delta_buffer.GetPercentile(base::TimeTicks(), &time_delta_result, 443 time_delta_buffer.GetPercentile(base::TimeTicks(), &time_delta_result,
445 i, disallowed_observation_sources)); 444 i, disallowed_observation_sources));
446 EXPECT_NEAR(time_delta_result.InMilliseconds(), 10000, 1); 445 EXPECT_NEAR(time_delta_result.InMilliseconds(), 10000, 1);
447 } 446 }
448 } 447 }
449 448
450 TEST(NetworkQualityObservationBufferTest, TestGetMedianRTTSince) { 449 TEST(NetworkQualityObservationBufferTest, TestGetMedianRTTSince) {
451 ObservationBuffer<int32_t> int_buffer(0.5); 450 ObservationBuffer<int32_t> int_buffer(0.5);
452 ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); 451 ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5);
453 base::TimeTicks now = base::TimeTicks::Now(); 452 base::TimeTicks now = base::TimeTicks::Now();
454 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1); 453 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1);
455 ASSERT_NE(old, now); 454 ASSERT_NE(old, now);
456 455
457 // First sample has very old timestamp. 456 // First sample has very old timestamp.
458 int_buffer.AddObservation(Observation<int32_t>( 457 int_buffer.AddObservation(
459 1, old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 458 Observation<int32_t>(1, old, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
460 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 459 time_delta_buffer.AddObservation(
461 base::TimeDelta::FromMilliseconds(1), old, 460 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(1), old,
462 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 461 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
463 462
464 int_buffer.AddObservation(Observation<int32_t>( 463 int_buffer.AddObservation(
465 100, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 464 Observation<int32_t>(100, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
466 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 465 time_delta_buffer.AddObservation(
467 base::TimeDelta::FromMilliseconds(100), now, 466 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(100), now,
468 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 467 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
469 468
470 const struct { 469 const struct {
471 base::TimeTicks start_timestamp; 470 base::TimeTicks start_timestamp;
472 bool expect_network_quality_available; 471 bool expect_network_quality_available;
473 base::TimeDelta expected_url_request_rtt; 472 base::TimeDelta expected_url_request_rtt;
474 int32_t expected_downstream_throughput; 473 int32_t expected_downstream_throughput;
475 } tests[] = { 474 } tests[] = {
476 {now + base::TimeDelta::FromSeconds(10), false, 475 {now + base::TimeDelta::FromSeconds(10), false,
477 base::TimeDelta::FromMilliseconds(0), 0}, 476 base::TimeDelta::FromMilliseconds(0), 0},
478 {now, true, base::TimeDelta::FromMilliseconds(100), 100}, 477 {now, true, base::TimeDelta::FromMilliseconds(100), 100},
(...skipping 24 matching lines...) Expand all
503 } 502 }
504 } 503 }
505 504
506 } // namespace 505 } // namespace
507 506
508 } // namespace internal 507 } // namespace internal
509 508
510 } // namespace nqe 509 } // namespace nqe
511 510
512 } // namespace net 511 } // namespace net
OLDNEW
« net/nqe/network_quality_observation_source.h ('K') | « net/nqe/network_quality_observation_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698