diff options
author | 2021-04-28 11:49:29 -0700 | |
---|---|---|
committer | 2021-04-28 15:09:58 -0400 | |
commit | f14d5f4af12eb521a5142151d6ea3addbbed42bb (patch) | |
tree | 526a1feb786c03f64ed29f97d395b18480311dac /absl/strings/cordz_test_helpers.h | |
parent | bcc11a8918f8cc9b43c9a0dc5da7b52d48452bd3 (diff) |
Export of internal Abseil changes
--
a78c34c705b15598ea00171d4ff8755e38fad863 by Derek Mauro <dmauro@google.com>:
Improve compiler support for ABSL_FALLTHROUGH_INTENDED
PiperOrigin-RevId: 370952333
--
aed0c26f1a2aac98e217ad1b44ce4a858780a223 by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation for Flatten
PiperOrigin-RevId: 370815149
--
ff4a58d0109d39dc32ef7a5e5e669ca4e630c6d9 by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to RemovePrefix and RemoveSuffix
PiperOrigin-RevId: 370751602
--
40220a058b30ddd89c6e547591488d15342137dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to operator=(string_view)
PiperOrigin-RevId: 370737600
--
a2e49604f18b92e50b179b5477dfddb8f57538ca by Martijn Vels <mvels@google.com>:
Add cordz instrumentation for Subcord
PiperOrigin-RevId: 370724107
--
bcc3902e04fb4f14270aef00e18908e6a88474cd by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 370707219
GitOrigin-RevId: a78c34c705b15598ea00171d4ff8755e38fad863
Change-Id: I0270e536cbdeaf1f195199da822b314521de3b96
Diffstat (limited to 'absl/strings/cordz_test_helpers.h')
-rw-r--r-- | absl/strings/cordz_test_helpers.h | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/absl/strings/cordz_test_helpers.h b/absl/strings/cordz_test_helpers.h index d9573c97..e410eecf 100644 --- a/absl/strings/cordz_test_helpers.h +++ b/absl/strings/cordz_test_helpers.h @@ -27,6 +27,7 @@ #include "absl/strings/internal/cordz_sample_token.h" #include "absl/strings/internal/cordz_statistics.h" #include "absl/strings/internal/cordz_update_tracker.h" +#include "absl/strings/str_cat.h" namespace absl { ABSL_NAMESPACE_BEGIN @@ -34,7 +35,7 @@ ABSL_NAMESPACE_BEGIN // Returns the CordzInfo for the cord, or nullptr if the cord is not sampled. inline const cord_internal::CordzInfo* GetCordzInfoForTesting( const Cord& cord) { - if (cord.size() <= cord_internal::kMaxInline) return nullptr; + if (!cord.contents_.is_tree()) return nullptr; return cord.contents_.cordz_info(); } @@ -47,13 +48,11 @@ inline bool CordzInfoIsListed(const cord_internal::CordzInfo* cordz_info, return false; } -// Matcher on Cord* that verifies all of: +// Matcher on Cord that verifies all of: // - the cord is sampled // - the CordzInfo of the cord is listed / discoverable. // - the reported CordzStatistics match the cord's actual properties // - the cord has an (initial) UpdateTracker count of 1 for `method` -// This matcher accepts a const Cord* to avoid having the matcher dump -// copious amounts of cord data on failures. MATCHER_P(HasValidCordzInfoOf, method, "CordzInfo matches cord") { const cord_internal::CordzInfo* cord_info = GetCordzInfoForTesting(arg); if (cord_info == nullptr) { @@ -78,6 +77,24 @@ MATCHER_P(HasValidCordzInfoOf, method, "CordzInfo matches cord") { return true; } +// Matcher on Cord that verifies that the cord is sampled and that the CordzInfo +// update tracker has 'method' with a call count of 'n' +MATCHER_P2(CordzMethodCountEq, method, n, + absl::StrCat("CordzInfo method count equals ", n)) { + const cord_internal::CordzInfo* cord_info = GetCordzInfoForTesting(arg); + if (cord_info == nullptr) { + *result_listener << "cord is not sampled"; + return false; + } + cord_internal::CordzStatistics stat = cord_info->GetCordzStatistics(); + if (stat.update_tracker.Value(method) != n) { + *result_listener << "Expected method count " << n << " for " << method + << ", found " << stat.update_tracker.Value(method); + return false; + } + return true; +} + // Cordz will only update with a new rate once the previously scheduled event // has fired. When we disable Cordz, a long delay takes place where we won't // consider profiling new Cords. CordzSampleIntervalHelper will burn through |