Skip to content

Commit

Permalink
roachtest: validate token return in perturbation/* tests
Browse files Browse the repository at this point in the history
This commit adds validation that all RAC tokens are returned on all
stable nodes at the end of the test.

Fixes: cockroachdb#133410

Release note: None
  • Loading branch information
andrewbaptist committed Oct 28, 2024
1 parent 2e1be7f commit 865919a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions pkg/cmd/roachtest/tests/admission_control_latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
"github.com/cockroachdb/cockroach/pkg/roachprod/install"
"github.com/cockroachdb/cockroach/pkg/roachprod/logger"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
"github.com/cockroachdb/cockroach/pkg/util/retry"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
Expand Down Expand Up @@ -901,6 +902,47 @@ func (v variations) runTest(ctx context.Context, t test.Test, c cluster.Cluster)
t.L().Printf("validating stats after the perturbation")
failures = append(failures, isAcceptableChange(t.L(), baselineStats, afterStats, v.acceptableChange)...)
require.True(t, len(failures) == 0, strings.Join(failures, "\n"))
v.validateTokensReturned(ctx, t)
}

// validateTokensReturned ensures that all RAC tokens are returned to the pool
// at the end of the test.
func (v variations) validateTokensReturned(ctx context.Context, t test.Test) {
t.L().Printf("validating all tokens returned")
for _, node := range v.stableNodes() {
// Wait for the tokens to be returned to the pool. Normally this will
// pass immediately however it is possible that there is still some
// recovery so loop a few times.
testutils.SucceedsWithin(t, func() error {
db := v.Conn(ctx, t.L(), node)
defer db.Close()
for _, sType := range []string{"send", "eval"} {
for _, tType := range []string{"elastic", "regular"} {
statPrefix := fmt.Sprintf("kvflowcontrol.tokens.%s.%s", sType, tType)
query := fmt.Sprintf(`
SELECT d.value::INT8 AS deducted, r.value::INT8 AS returned
FROM
crdb_internal.node_metrics d,
crdb_internal.node_metrics r
WHERE
d.name='%s.deducted' AND
r.name='%s.returned'`,
statPrefix, statPrefix)
rows, err := db.QueryContext(ctx, query)
require.NoError(t, err)
require.True(t, rows.Next())
var deducted, returned int64
if err := rows.Scan(&deducted, &returned); err != nil {
return err
}
if deducted != returned {
return errors.Newf("tokens not returned for %s: deducted %d returned %d", statPrefix, deducted, returned)
}
}
}
return nil
}, 5*time.Second)
}
}

// trackedStat is a collection of the relevant values from the histogram. The
Expand Down

0 comments on commit 865919a

Please sign in to comment.