aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/debug
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-09-05 12:10:18 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-09-05 12:10:18 -0700
commit83db6312c60859002d4bb2c301f594fc65039ecf (patch)
tree350f5018de6ecedae75c2b9f33027ab95dad10f3 /test/core/debug
parentc75f9868c3be5680eb33e1a6f1b8be7b9723a874 (diff)
Optimize test
Diffstat (limited to 'test/core/debug')
-rw-r--r--test/core/debug/stats_test.cc29
1 files changed, 13 insertions, 16 deletions
diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc
index 65ccc7a5c8..82ed27cb13 100644
--- a/test/core/debug/stats_test.cc
+++ b/test/core/debug/stats_test.cc
@@ -73,30 +73,29 @@ static int FindExpectedBucket(int i, int j) {
grpc_stats_histo_bucket_boundaries[i][grpc_stats_histo_buckets[i] - 1]) {
return grpc_stats_histo_buckets[i] - 1;
}
- int r = 0;
- while (grpc_stats_histo_bucket_boundaries[i][r + 1] <= j) r++;
- return r;
-}
-
-static int FindNonZeroBucket(const grpc_stats_data& data, int i) {
- for (int j = 0; j < grpc_stats_histo_buckets[i]; j++) {
- if (data.histograms[grpc_stats_histo_start[i] + j] != 0) {
- return j;
- }
- }
- return -1;
+ return std::upper_bound(grpc_stats_histo_bucket_boundaries[i],
+ grpc_stats_histo_bucket_boundaries[i] +
+ grpc_stats_histo_buckets[i],
+ j) -
+ grpc_stats_histo_bucket_boundaries[i] - 1;
}
TEST(StatsTest, IncHistogram) {
for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) {
+ std::vector<int> test_values;
for (int j = -1000;
j <
grpc_stats_histo_bucket_boundaries[i]
[grpc_stats_histo_buckets[i] - 1] +
1000;
j++) {
- gpr_log(GPR_DEBUG, "histo:%d value:%d", i, j);
-
+ test_values.push_back(j);
+ }
+ std::random_shuffle(test_values.begin(), test_values.end());
+ if (test_values.size() > 10000) {
+ test_values.resize(10000);
+ }
+ for (auto j : test_values) {
Snapshot snapshot;
int expected_bucket = FindExpectedBucket(i, j);
@@ -106,9 +105,7 @@ TEST(StatsTest, IncHistogram) {
grpc_exec_ctx_finish(&exec_ctx);
auto delta = snapshot.delta();
- int got_bucket = FindNonZeroBucket(delta, i);
- EXPECT_EQ(expected_bucket, got_bucket);
EXPECT_EQ(delta.histograms[grpc_stats_histo_start[i] + expected_bucket],
1);
}