src/net/nqe/observation_buffer_unittest.cc
// Verifies that the percentiles are correctly computed when results must be
// update for each individual host. All observations can have the same timestamp
// or different timestamps.
Verifies that the percentiles are correctly computed when results must be
update for each individual host. All observations can have the same timestamp
or different timestamps.
Verifies that the percentiles are correctly computed when results must be update for each individual host . All observations can have the same timestamp or different timestamps .
TEST(NetworkQualityObservationBufferTest, GetPercentileStatsForAllHosts) {
  std::map<std::string, std::string> variation_params;
  NetworkQualityEstimatorParams params(variation_params);
  base::SimpleTestTickClock tick_clock;
  tick_clock.Advance(base::TimeDelta::FromMinutes(1));
  ObservationBuffer mixed_buffer(&params, &tick_clock, 0.5, 1.0);
  const base::TimeTicks now = tick_clock.NowTicks();
  const base::TimeTicks history = now - base::TimeDelta::FromMilliseconds(1);
  const base::TimeTicks future = now + base::TimeDelta::FromMilliseconds(1);
  const uint64_t host_1 = 0x101010UL;
  const uint64_t host_2 = 0x202020UL;
  const size_t total_observaions_count = 100;
  for (size_t i = 1; i <= total_observaions_count; ++i) {
    mixed_buffer.AddObservation(Observation(
        i, now, INT32_MIN, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP, host_1));
    mixed_buffer.AddObservation(
        Observation((i + 1) / 2, now, INT32_MIN,
                    NETWORK_QUALITY_OBSERVATION_SOURCE_TCP, host_2));
  }
  EXPECT_EQ(total_observaions_count * 2, mixed_buffer.Size());
  std::set<uint64_t> empty_hosts_set;
  std::map<uint64_t, CanonicalStats> recent_rtt_stats =
      mixed_buffer.GetCanonicalStatsKeyedByHosts(history, empty_hosts_set);
  EXPECT_EQ(2u, recent_rtt_stats.size());
  EXPECT_EQ(total_observaions_count,
            recent_rtt_stats[host_1].observation_count);
  EXPECT_EQ(total_observaions_count,
            recent_rtt_stats[host_2].observation_count);
  EXPECT_EQ(1, recent_rtt_stats[host_1].canonical_pcts[kStatVal0p]);
  EXPECT_EQ(5, recent_rtt_stats[host_1].canonical_pcts[kStatVal5p]);
  EXPECT_EQ(50, recent_rtt_stats[host_1].canonical_pcts[kStatVal50p]);
  EXPECT_EQ(95, recent_rtt_stats[host_1].canonical_pcts[kStatVal95p]);
  EXPECT_EQ(99, recent_rtt_stats[host_1].canonical_pcts[kStatVal99p]);
  EXPECT_EQ(1, recent_rtt_stats[host_2].canonical_pcts[kStatVal0p]);
  EXPECT_EQ(3, recent_rtt_stats[host_2].canonical_pcts[kStatVal5p]);
  EXPECT_EQ(25, recent_rtt_stats[host_2].canonical_pcts[kStatVal50p]);
  EXPECT_EQ(48, recent_rtt_stats[host_2].canonical_pcts[kStatVal95p]);
  EXPECT_EQ(50, recent_rtt_stats[host_2].canonical_pcts[kStatVal99p]);
  recent_rtt_stats =
      mixed_buffer.GetCanonicalStatsKeyedByHosts(future, empty_hosts_set);
  EXPECT_TRUE(recent_rtt_stats.empty());
  std::set<uint64_t> target_hosts_set = {host_1};
  recent_rtt_stats =
      mixed_buffer.GetCanonicalStatsKeyedByHosts(history, target_hosts_set);
  EXPECT_EQ(1u, recent_rtt_stats.size());
  EXPECT_EQ(total_observaions_count,
            recent_rtt_stats[host_1].observation_count);
  EXPECT_EQ(1, recent_rtt_stats[host_1].canonical_pcts[kStatVal0p]);
  EXPECT_EQ(5, recent_rtt_stats[host_1].canonical_pcts[kStatVal5p]);
  EXPECT_EQ(50, recent_rtt_stats[host_1].canonical_pcts[kStatVal50p]);
  EXPECT_EQ(95, recent_rtt_stats[host_1].canonical_pcts[kStatVal95p]);
  EXPECT_EQ(99, recent_rtt_stats[host_1].canonical_pcts[kStatVal99p]);
  EXPECT_TRUE(recent_rtt_stats.find(host_2) == recent_rtt_stats.end());
  bool deleted_observation_sources[NETWORK_QUALITY_OBSERVATION_SOURCE_MAX] = {
      false};
  deleted_observation_sources[NETWORK_QUALITY_OBSERVATION_SOURCE_TCP] = true;
  mixed_buffer.RemoveObservationsWithSource(deleted_observation_sources);
  EXPECT_EQ(0u, mixed_buffer.Size());
}
TEST ( NetworkQualityObservationBufferTest , GetPercentileStatsForAllHosts ) { std :: map < std :: string , std :: string > variation_params ; NetworkQualityEstimatorParams params ( variation_params ) ; base :: SimpleTestTickClock tick_clock ; tick_clock . Advance ( base :: TimeDelta :: FromMinutes ( 1 ) ) ; ObservationBuffer mixed_buffer ( & params , & tick_clock , 0.5 , 1.0 ) ; const base :: TimeTicks now = tick_clock . NowTicks ( ) ; const base :: TimeTicks history = now - base :: TimeDelta :: FromMilliseconds ( 1 ) ; const base :: TimeTicks future = now + base :: TimeDelta :: FromMilliseconds ( 1 ) ; const uint64_t host_1 = 0x101010UL ; const uint64_t host_2 = 0x202020UL ; const size_t total_observaions_count = 100 ; for ( size_t i = 1 ; i <= total_observaions_count ; ++ i ) { mixed_buffer . AddObservation ( Observation ( i , now , INT32_MIN , NETWORK_QUALITY_OBSERVATION_SOURCE_TCP , host_1 ) ) ; mixed_buffer . AddObservation ( Observation ( ( i + 1 ) / 2 , now , INT32_MIN , NETWORK_QUALITY_OBSERVATION_SOURCE_TCP , host_2 ) ) ; } EXPECT_EQ ( total_observaions_count * 2 , mixed_buffer . Size ( ) ) ; std :: set < uint64_t > empty_hosts_set ; std :: map < uint64_t , CanonicalStats > recent_rtt_stats = mixed_buffer . GetCanonicalStatsKeyedByHosts ( history , empty_hosts_set ) ; EXPECT_EQ ( 2u , recent_rtt_stats . size ( ) ) ; EXPECT_EQ ( total_observaions_count , recent_rtt_stats [ host_1 ] . observation_count ) ; EXPECT_EQ ( total_observaions_count , recent_rtt_stats [ host_2 ] . observation_count ) ; EXPECT_EQ ( 1 , recent_rtt_stats [ host_1 ] . canonical_pcts [ kStatVal0p ] ) ; EXPECT_EQ ( 5 , recent_rtt_stats [ host_1 ] . canonical_pcts [ kStatVal5p ] ) ; EXPECT_EQ ( 50 , recent_rtt_stats [ host_1 ] . canonical_pcts [ kStatVal50p ] ) ; EXPECT_EQ ( 95 , recent_rtt_stats [ host_1 ] . canonical_pcts [ kStatVal95p ] ) ; EXPECT_EQ ( 99 , recent_rtt_stats [ host_1 ] . canonical_pcts [ kStatVal99p ] ) ; EXPECT_EQ ( 1 , recent_rtt_stats [ host_2 ] . canonical_pcts [ kStatVal0p ] ) ; EXPECT_EQ ( 3 , recent_rtt_stats [ host_2 ] . canonical_pcts [ kStatVal5p ] ) ; EXPECT_EQ ( 25 , recent_rtt_stats [ host_2 ] . canonical_pcts [ kStatVal50p ] ) ; EXPECT_EQ ( 48 , recent_rtt_stats [ host_2 ] . canonical_pcts [ kStatVal95p ] ) ; EXPECT_EQ ( 50 , recent_rtt_stats [ host_2 ] . canonical_pcts [ kStatVal99p ] ) ; recent_rtt_stats = mixed_buffer . GetCanonicalStatsKeyedByHosts ( future , empty_hosts_set ) ; EXPECT_TRUE ( recent_rtt_stats . empty ( ) ) ; std :: set < uint64_t > target_hosts_set = { host_1 } ; recent_rtt_stats = mixed_buffer . GetCanonicalStatsKeyedByHosts ( history , target_hosts_set ) ; EXPECT_EQ ( 1u , recent_rtt_stats . size ( ) ) ; EXPECT_EQ ( total_observaions_count , recent_rtt_stats [ host_1 ] . observation_count ) ; EXPECT_EQ ( 1 , recent_rtt_stats [ host_1 ] . canonical_pcts [ kStatVal0p ] ) ; EXPECT_EQ ( 5 , recent_rtt_stats [ host_1 ] . canonical_pcts [ kStatVal5p ] ) ; EXPECT_EQ ( 50 , recent_rtt_stats [ host_1 ] . canonical_pcts [ kStatVal50p ] ) ; EXPECT_EQ ( 95 , recent_rtt_stats [ host_1 ] . canonical_pcts [ kStatVal95p ] ) ; EXPECT_EQ ( 99 , recent_rtt_stats [ host_1 ] . canonical_pcts [ kStatVal99p ] ) ; EXPECT_TRUE ( recent_rtt_stats . find ( host_2 ) == recent_rtt_stats . end ( ) ) ; bool deleted_observation_sources [ NETWORK_QUALITY_OBSERVATION_SOURCE_MAX ] = { false } ; deleted_observation_sources [ NETWORK_QUALITY_OBSERVATION_SOURCE_TCP ] = true ; mixed_buffer . RemoveObservationsWithSource ( deleted_observation_sources ) ; EXPECT_EQ ( 0u , mixed_buffer . Size ( ) ) ; }
Verifies that the percentiles are correctly computed when results must be
update for each individual host.
Verifies that the percentiles are correctly computed when results must be update for each individual host .
// The observation buffer holds mixed observations for different hosts. // Inserts samples from {1,2,3,...,100} for |host_1|. Insert samples from // {1,1,2,2,3,3,...,50,50} for |host_2|. Verifies all percentiles are // computed correctly for both hosts. // All observations are categories into two groups keyed by two hosts. // In each group, all percentile statistics are updated and the number of // available observations are also updated correctly. // Checks all canonical percentile values are correct. // For |host_1|, percentile_val = percentile. // For |host_2|, percentile_val = (percentile + 1) / 2. // Checks results are cleared because all buffered observations expire. // Expects the result map is empty. // Checks results contain stats only for hosts that were in the set. // Checks that host 2 does not present in the results.