@@ -484,25 +484,17 @@ func TestDistSQLReceiverErrorRanking(t *testing.T) {
484484
485485// TestDistSQLReceiverReportsContention verifies that the distsql receiver
486486// reports contention events via an observable metric if they occur. This test
487- // additionally verifies that the metric stays at zero if there is no
488- // contention.
487+ // additionally verifies that if there is no contention on user tables, the
488+ // contention registry doesn't report any events .
489489func TestDistSQLReceiverReportsContention (t * testing.T ) {
490490 defer leaktest .AfterTest (t )()
491491 defer log .Scope (t ).Close (t )
492492
493493 ctx := context .Background ()
494494 testutils .RunTrueAndFalse (t , "contention" , func (t * testing.T , contention bool ) {
495- // TODO(yuzefovich): add an onContentionEventCb() to
496- // DistSQLRunTestingKnobs and use it here to accumulate contention
497- // events.
498495 s , db , _ := serverutils .StartServer (t , base.TestServerArgs {})
499496 defer s .Stopper ().Stop (ctx )
500497
501- // Disable sampling so that only our query (below) gets a trace.
502- // Otherwise, we're subject to flakes when internal queries experience contention.
503- _ , err := db .Exec ("SET CLUSTER SETTING sql.txn_stats.sample_rate = 0" )
504- require .NoError (t , err )
505-
506498 sqlutils .CreateTable (
507499 t , db , "test" , "x INT PRIMARY KEY" , 1 , sqlutils .ToRowFn (sqlutils .RowIdxFn ),
508500 )
@@ -514,9 +506,6 @@ func TestDistSQLReceiverReportsContention(t *testing.T) {
514506 // Begin a contending transaction.
515507 conn , err := db .Conn (ctx )
516508 require .NoError (t , err )
517- defer func () {
518- require .NoError (t , conn .Close ())
519- }()
520509 _ , err = conn .ExecContext (ctx , "BEGIN; UPDATE test.test SET x = 10 WHERE x = 1;" )
521510 require .NoError (t , err )
522511 }
@@ -527,11 +516,6 @@ func TestDistSQLReceiverReportsContention(t *testing.T) {
527516 contentionRegistry := s .ExecutorConfig ().(ExecutorConfig ).ContentionRegistry
528517 otherConn , err := db .Conn (ctx )
529518 require .NoError (t , err )
530- defer func () {
531- require .NoError (t , otherConn .Close ())
532- }()
533- // TODO(yuzefovich): turning the tracing ON won't be necessary once
534- // always-on tracing is enabled.
535519 _ , err = otherConn .ExecContext (ctx , `SET TRACING=on;` )
536520 require .NoError (t , err )
537521 txn , err := otherConn .BeginTx (ctx , nil )
@@ -540,23 +524,21 @@ func TestDistSQLReceiverReportsContention(t *testing.T) {
540524 SET TRANSACTION PRIORITY HIGH;
541525 UPDATE test.test SET x = 100 WHERE x = 1;
542526 ` )
543-
544527 require .NoError (t , err )
528+
545529 if contention {
546530 // Soft check to protect against flakiness where an internal query
547531 // causes the contention metric to increment.
548532 require .GreaterOrEqual (t , metrics .ContendedQueriesCount .Count (), int64 (1 ))
549533 require .Positive (t , metrics .CumulativeContentionNanos .Count ())
550- } else {
551- require .Zero (
552- t ,
553- metrics .ContendedQueriesCount .Count (),
554- "contention metric unexpectedly non-zero when no contention events are produced" ,
555- )
556- require .Zero (t , metrics .CumulativeContentionNanos .Count ())
557534 }
558-
535+ // Note that in the contention=false case, we've seen flakes where
536+ // contention on system tables occasionally shows up. In that scenario,
537+ // this check is the meat of the test - we're ensuring that if we didn't
538+ // explicitly create contention, then we don't see our table in the
539+ // contention registry.
559540 require .Equal (t , contention , strings .Contains (contentionRegistry .String (), contentionEventSubstring ))
541+
560542 err = txn .Commit ()
561543 require .NoError (t , err )
562544 _ , err = otherConn .ExecContext (ctx , `SET TRACING=off;` )
0 commit comments