Skip to content

Commit

Permalink
kvserver: minor test simplification
Browse files Browse the repository at this point in the history
This test was jumping through hoops in order to combine a cluster
stopper, with its own Tracer, with calling into a node, which has a
different Tracer. Normally combining Tracers like that is illegal, but
the test was making sure to force the Stopper to create "sterile" spans
for its tasks, which are exempt from this restriction about combining
them with other Tracers, for arcane reasons. This patch switches the
test to a more straight-forward hoop: don't use a context created by the
stopper when calling into the node. Besides being simpler, this is
needed cause the exception for sterile spans is going away.

Release note: None
Epic: None
  • Loading branch information
andreimatei committed Dec 10, 2022
1 parent 557a588 commit ac3e298
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pkg/kv/kvserver/consistency_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,22 +542,25 @@ func testConsistencyQueueRecomputeStatsImpl(t *testing.T, hadEstimates bool) {
// RecomputeStats does not see any skew in its MVCC stats when they are
// modified concurrently. Note that these writes don't interfere with the
// field we modified (SysCount).
//
// We want to run this task under the cluster's stopper, as opposed to the
// first node's stopper, so that the quiesce signal is delivered below before
// individual nodes start shutting down.
_ = tc.Stopper().RunAsyncTaskEx(ctx,
stop.TaskOpts{
TaskName: "recompute-loop",
// We want to run this task under the cluster's stopper, so that the
// quiesce signal is delivered below before individual nodes start
// shutting down. Since we're going to operate on a specific node, we
// can't mix the cluster stopper's tracer with the node's tracer, hence
// the Sterile option.
SpanOpt: stop.SterileRootSpan,
}, func(ctx context.Context) {
}, func(_ context.Context) {
// This channel terminates the loop early if the test takes more than five
// seconds. This is useful for stress race runs in CI where the tight loop
// can starve the actual work to be done.
done := time.After(5 * time.Second)
for {
require.NoError(t, db0.Put(ctx, fmt.Sprintf("%s%d", key, rand.Int63()), "ballast"))
// We're using context.Background for the KV call. As explained above,
// this task runs on the cluster's stopper, and so the ctx that was
// passed to this function has a span created with a Tracer that's
// different from the first node's Tracer. If we used the ctx, we'd be
// combining Tracers in the trace, which is illegal.
require.NoError(t, db0.Put(context.Background(), fmt.Sprintf("%s%d", key, rand.Int63()), "ballast"))
select {
case <-tc.Stopper().ShouldQuiesce():
return
Expand Down

0 comments on commit ac3e298

Please sign in to comment.