From 65a29ec8d4d892d735caeb4ee993b9e411e9c1f9 Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Fri, 24 Sep 2021 21:01:35 +0000 Subject: [PATCH] kv: deflake TestTenantRateLimiter A recent change (#70328) increased the rate limit and that exposed a fragility in this test. This change restores the test to use the original (small) rate limit. Fixes #70456. Release note: None Release justification: test-only fix. --- pkg/kv/kvserver/client_tenant_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/kv/kvserver/client_tenant_test.go b/pkg/kv/kvserver/client_tenant_test.go index 41b92928de7f..8f4789b218c7 100644 --- a/pkg/kv/kvserver/client_tenant_test.go +++ b/pkg/kv/kvserver/client_tenant_test.go @@ -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) @@ -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 { @@ -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) }