Skip to content

Commit f56a4f4

Browse files
craig[bot]stevendanna
andcommitted
Merge #155703
155703: kvserver: small cleanup in TestTenantCtx r=arulajmani a=stevendanna This test recently failed during the CI run of an unrelated PR with the following error: expected Scan to run as the expected tenant ({10}), but it isn't. tenant request: false, tenantID: {0} However, _in addition_ the test also hit a panic because it was accessing a nil tx2 because it used assert.NoError rather than require.NoError. Here, I re-arrange the test a bit to avoid this. It doesn't solve whatever cause the original failure though, which doesn't seem to what to reproduce under stress yet. Epic: none Release note: None Co-authored-by: Steven Danna <danna@cockroachlabs.com>
2 parents 3a91af6 + b9ed3d1 commit f56a4f4

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

pkg/kv/kvserver/client_tenant_test.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
3636
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
3737
"github.com/cockroachdb/cockroach/pkg/upgrade/upgradebase"
38+
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
3839
"github.com/cockroachdb/cockroach/pkg/util/encoding"
3940
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
4041
"github.com/cockroachdb/cockroach/pkg/util/log"
@@ -482,16 +483,19 @@ func TestTenantCtx(t *testing.T) {
482483
_, err = tx1.Exec("insert into t(x) values ($1)", magicKey)
483484
require.NoError(t, err)
484485

485-
var tx2 *gosql.Tx
486-
var tx2C = make(chan struct{})
487-
go func() {
488-
var err error
489-
tx2, err = tsql.BeginTx(ctx, nil /* opts */)
490-
assert.NoError(t, err)
486+
g := ctxgroup.WithContext(ctx)
487+
g.Go(func() error {
488+
tx2, err := tsql.BeginTx(ctx, nil /* opts */)
489+
if err != nil {
490+
return err
491+
}
492+
// This SELECT should be blocked by the insert on tx1.
491493
_, err = tx2.Exec("select * from t where x = $1", magicKey)
492-
assert.NoError(t, err)
493-
close(tx2C)
494-
}()
494+
if err != nil {
495+
return err
496+
}
497+
return tx2.Rollback()
498+
})
495499

496500
// Wait for tx2 goroutine to send the PushTxn request, and then roll back tx1
497501
// to unblock tx2.
@@ -507,9 +511,7 @@ func TestTenantCtx(t *testing.T) {
507511
case <-time.After(3 * time.Second):
508512
t.Fatal("timed out waiting for PushTxn")
509513
}
510-
_ = tx1.Rollback()
511-
// Wait for tx2 to be unblocked.
512-
<-tx2C
513-
_ = tx2.Rollback()
514+
require.NoError(t, tx1.Rollback())
515+
require.NoError(t, g.Wait())
514516
})
515517
}

0 commit comments

Comments
 (0)