src/net/nqe/observation_buffer_unittest.cc
// Verifies that the percentiles are correctly computed when some of the
// observation sources are disallowed. All observations have the same timestamp.
Verifies that the percentiles are correctly computed when some of the
observation sources are disallowed. All observations have the same timestamp.
Verifies that the percentiles are correctly computed when some of the observation sources are disallowed . All observations have the same timestamp .
TEST(NetworkQualityObservationBufferTest, RemoveObservations) {
  std::map<std::string, std::string> variation_params;
  NetworkQualityEstimatorParams params(variation_params);
  base::SimpleTestTickClock tick_clock;
  tick_clock.Advance(base::TimeDelta::FromMinutes(1));
  ObservationBuffer buffer(&params, &tick_clock, 0.5, 1.0);
  const base::TimeTicks now = tick_clock.NowTicks();
  for (int i = 1; i <= 99; i += 2) {
    buffer.AddObservation(Observation(i, now, INT32_MIN,
                                      NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
  }
  EXPECT_EQ(50u, buffer.Size());
  for (int i = 1; i <= 99; i += 2) {
    buffer.AddObservation(Observation(10000, now, INT32_MIN,
                                      NETWORK_QUALITY_OBSERVATION_SOURCE_TCP));
    buffer.AddObservation(Observation(10000, now, INT32_MIN,
                                      NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC));
  }
  EXPECT_EQ(150u, buffer.Size());
  for (int i = 2; i <= 100; i += 2) {
    buffer.AddObservation(Observation(i, now, INT32_MIN,
                                      NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
  }
  EXPECT_EQ(200u, buffer.Size());
  bool deleted_observation_sources[NETWORK_QUALITY_OBSERVATION_SOURCE_MAX] = {
      false};
  buffer.RemoveObservationsWithSource(deleted_observation_sources);
  EXPECT_EQ(200u, buffer.Size());
  deleted_observation_sources[NETWORK_QUALITY_OBSERVATION_SOURCE_TCP] = true;
  deleted_observation_sources[NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC] = true;
  buffer.RemoveObservationsWithSource(deleted_observation_sources);
  EXPECT_EQ(100u, buffer.Size());
  for (int i = 0; i <= 100; ++i) {
    base::Optional<int32_t> result =
        buffer.GetPercentile(base::TimeTicks(), INT32_MIN, i,
                             nullptr);
    EXPECT_TRUE(result.has_value());
    EXPECT_NEAR(result.value(), i, 1);
  }
  deleted_observation_sources[NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP] = true;
  buffer.RemoveObservationsWithSource(deleted_observation_sources);
  EXPECT_EQ(0u, buffer.Size());
}
TEST ( NetworkQualityObservationBufferTest , RemoveObservations ) { std :: map < std :: string , std :: string > variation_params ; NetworkQualityEstimatorParams params ( variation_params ) ; base :: SimpleTestTickClock tick_clock ; tick_clock . Advance ( base :: TimeDelta :: FromMinutes ( 1 ) ) ; ObservationBuffer buffer ( & params , & tick_clock , 0.5 , 1.0 ) ; const base :: TimeTicks now = tick_clock . NowTicks ( ) ; for ( int i = 1 ; i <= 99 ; i += 2 ) { buffer . AddObservation ( Observation ( i , now , INT32_MIN , NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP ) ) ; } EXPECT_EQ ( 50u , buffer . Size ( ) ) ; for ( int i = 1 ; i <= 99 ; i += 2 ) { buffer . AddObservation ( Observation ( 10000 , now , INT32_MIN , NETWORK_QUALITY_OBSERVATION_SOURCE_TCP ) ) ; buffer . AddObservation ( Observation ( 10000 , now , INT32_MIN , NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC ) ) ; } EXPECT_EQ ( 150u , buffer . Size ( ) ) ; for ( int i = 2 ; i <= 100 ; i += 2 ) { buffer . AddObservation ( Observation ( i , now , INT32_MIN , NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP ) ) ; } EXPECT_EQ ( 200u , buffer . Size ( ) ) ; bool deleted_observation_sources [ NETWORK_QUALITY_OBSERVATION_SOURCE_MAX ] = { false } ; buffer . RemoveObservationsWithSource ( deleted_observation_sources ) ; EXPECT_EQ ( 200u , buffer . Size ( ) ) ; deleted_observation_sources [ NETWORK_QUALITY_OBSERVATION_SOURCE_TCP ] = true ; deleted_observation_sources [ NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC ] = true ; buffer . RemoveObservationsWithSource ( deleted_observation_sources ) ; EXPECT_EQ ( 100u , buffer . Size ( ) ) ; for ( int i = 0 ; i <= 100 ; ++ i ) { base :: Optional < int32_t > result = buffer . GetPercentile ( base :: TimeTicks ( ) , INT32_MIN , i , nullptr ) ; EXPECT_TRUE ( result . has_value ( ) ) ; EXPECT_NEAR ( result . value ( ) , i , 1 ) ; } deleted_observation_sources [ NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP ] = true ; buffer . RemoveObservationsWithSource ( deleted_observation_sources ) ; EXPECT_EQ ( 0u , buffer . Size ( ) ) ; }
Verifies that the percentiles are correctly computed when some of the
observation sources are disallowed.
Verifies that the percentiles are correctly computed when some of the observation sources are disallowed .
// Insert samples from {1,2,3,..., 100}. First insert odd samples, then even // samples. This helps in verifying that the order of samples does not matter. // Add samples for TCP and QUIC observations which should not be taken into // account when computing the percentile. // Since all entries in |deleted_observation_sources| are set to false, no // observations should be deleted. // 50 TCP and 50 QUIC observations should be deleted. // Checks if the difference between the two integers is less than 1. This is // required because computed percentiles may be slightly different from // what is expected due to floating point computation errors and integer // rounding off errors.