From 3cf8d50d1ecc3e9c2dc756cff4d1ff9fcb6c80b9 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Sun, 8 Oct 2017 05:11:15 +0000 Subject: [PATCH] accurate, exhaustive "fast" version of this test --- build.yaml | 1 + test/core/debug/stats_test.cc | 58 ++++++++++++++-------------- tools/run_tests/generated/tests.json | 1 + tools/run_tests/run_tests.py | 2 +- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/build.yaml b/build.yaml index 211cf6913fd..1cb00ec146f 100644 --- a/build.yaml +++ b/build.yaml @@ -4607,6 +4607,7 @@ targets: - grpc - gpr_test_util - gpr + timeout_seconds: 1200 uses_polling: false - name: status_test build: test diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc index c652e446b8e..db9105672ee 100644 --- a/test/core/debug/stats_test.cc +++ b/test/core/debug/stats_test.cc @@ -87,42 +87,42 @@ class HistogramTest : public ::testing::TestWithParam {}; TEST_P(HistogramTest, IncHistogram) { const int kHistogram = GetParam(); - const int kBuckets = grpc_stats_histo_buckets[kHistogram]; - const int kThreads = kBuckets; std::vector threads; - std::vector mutexes(kBuckets); - for (int thread = 0; thread < kThreads; thread++) { - threads.emplace_back([kHistogram, kThreads, thread, &mutexes]() { + int cur_bucket = 0; + auto run = [kHistogram](const std::vector& test_values, int expected_bucket) { + gpr_log(GPR_DEBUG, "expected_bucket:%d nvalues=%" PRIdPTR, expected_bucket, test_values.size()); + for (auto j : test_values) { + Snapshot snapshot; + + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_stats_inc_histogram[kHistogram](&exec_ctx, j); + grpc_exec_ctx_finish(&exec_ctx); + + auto delta = snapshot.delta(); + + EXPECT_EQ(delta.histograms[grpc_stats_histo_start[kHistogram] + + expected_bucket], + 1) + << "\nhistogram:" << kHistogram + << "\nexpected_bucket:" << expected_bucket + << "\nj:" << j; + } + }; std::vector test_values; - for (int j = -1000 + thread; + for (int j = -1000; j < grpc_stats_histo_bucket_boundaries [kHistogram][grpc_stats_histo_buckets[kHistogram] - 1] + 1000; - j += kThreads) { + j ++) { + int expected_bucket = FindExpectedBucket(kHistogram, j); + if (cur_bucket != expected_bucket) { + threads.emplace_back([test_values, run, cur_bucket]() { run(test_values, cur_bucket); }); + cur_bucket = expected_bucket; + test_values.clear(); + } test_values.push_back(j); } - std::random_shuffle(test_values.begin(), test_values.end()); - for (auto j : test_values) { - int expected_bucket = FindExpectedBucket(kHistogram, j); - std::lock_guard lock(mutexes[expected_bucket]); - - Snapshot snapshot; - - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_stats_inc_histogram[kHistogram](&exec_ctx, j); - grpc_exec_ctx_finish(&exec_ctx); - - auto delta = snapshot.delta(); - - EXPECT_EQ(delta.histograms[grpc_stats_histo_start[kHistogram] + - expected_bucket], - 1) - << "\nhistogram:" << kHistogram - << "\nexpected_bucket:" << expected_bucket << "\nthread:" << thread - << "\nj:" << j; - } - }); - } + run(test_values, cur_bucket); for (auto& t : threads) { t.join(); } diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 72e840e2f20..fa75017781e 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -4195,6 +4195,7 @@ "posix", "windows" ], + "timeout_seconds": 1200, "uses_polling": false }, { diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 7c65067857f..6bdd8be7e95 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -353,7 +353,7 @@ class CLanguage(object): out.append(self.config.job_spec(cmdline, shortname='%s %s' % (' '.join(cmdline), shortname_ext), cpu_cost=cpu_cost, - timeout_seconds=_DEFAULT_TIMEOUT_SECONDS * timeout_scaling, + timeout_seconds=target.get('timeout_seconds', _DEFAULT_TIMEOUT_SECONDS) * timeout_scaling, environ=env)) else: cmdline = [binary] + target['args']