Skip to content

Commit

Permalink
Merge pull request #70737 from cockroachdb/blathers/backport-release-…
Browse files Browse the repository at this point in the history
…21.2-70723

release-21.2: kv: deflake TestTenantRateLimiter
  • Loading branch information
RaduBerinde authored Sep 28, 2021
2 parents 9336e93 + 65a29ec commit 2fef2fb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/kv/kvserver/client_tenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ func TestTenantRateLimiter(t *testing.T) {
ctx := context.Background()
defer s.Stopper().Stop(ctx)

// Set a small rate limit so the test doesn't take a long time.
runner := sqlutils.MakeSQLRunner(sqlDB)
runner.Exec(t, `SET CLUSTER SETTING kv.tenant_rate_limiter.rate_limit = 200`)

tenantID := serverutils.TestTenantID()
codec := keys.MakeSQLCodec(tenantID)

Expand Down Expand Up @@ -222,8 +226,7 @@ func TestTenantRateLimiter(t *testing.T) {

// Create some tooling to read and verify metrics off of the prometheus
// endpoint.
sqlutils.MakeSQLRunner(sqlDB).Exec(t,
`SET CLUSTER SETTING server.child_metrics.enabled = true`)
runner.Exec(t, `SET CLUSTER SETTING server.child_metrics.enabled = true`)
httpClient, err := s.GetHTTPClient()
require.NoError(t, err)
getMetrics := func() string {
Expand All @@ -245,5 +248,9 @@ func TestTenantRateLimiter(t *testing.T) {

// Ensure that the metric for the admitted requests reflects the number of
// admitted requests.
require.Contains(t, getMetrics(), makeMetricStr(int64(tooManyWrites)))
// TODO(radu): this is fragile because a background write could sneak in and
// the count wouldn't match exactly.
m := getMetrics()
exp := makeMetricStr(int64(tooManyWrites))
require.Contains(t, m, exp, "could not find %s in metrics: \n%s\n", exp, m)
}

0 comments on commit 2fef2fb

Please sign in to comment.