@@ -38,6 +38,7 @@ import (
38
38
"github.com/cockroachdb/cockroach/pkg/util/log"
39
39
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
40
40
"github.com/cockroachdb/cockroach/pkg/util/uuid"
41
+ "github.com/cockroachdb/errors"
41
42
"github.com/stretchr/testify/require"
42
43
)
43
44
@@ -803,7 +804,6 @@ func TestInsightsIntegrationForContention(t *testing.T) {
803
804
// Chan to wait for the txn to complete to avoid checking for insights before the txn is committed.
804
805
txnDoneChan := make (chan struct {})
805
806
806
- observerConn := sqlutils .MakeSQLRunner (tc .ApplicationLayer (0 ).SQLConn (t ))
807
807
txConn := sqlutils .MakeSQLRunner (tc .ApplicationLayer (0 ).SQLConn (t ))
808
808
tx := txConn .Begin (t )
809
809
@@ -828,10 +828,20 @@ func TestInsightsIntegrationForContention(t *testing.T) {
828
828
require .NoError (t , errTxn )
829
829
830
830
var waitingTxnID uuid.UUID
831
- observerConn . QueryRow (t ,
832
- `SELECT id
831
+ testutils . SucceedsSoon (t , func () error {
832
+ r , err := tc . ApplicationLayer ( 0 ). SQLConn ( t ). Query ( `SELECT id
833
833
FROM crdb_internal.node_transactions
834
- WHERE application_name = 'waiting_txn'` ).Scan (& waitingTxnID )
834
+ WHERE application_name = 'waiting_txn'` )
835
+ require .NoError (t , err )
836
+ defer r .Close ()
837
+
838
+ if ! r .Next () {
839
+ return errors .New ("waiting_txn not found" )
840
+ }
841
+ err = r .Scan (& waitingTxnID )
842
+ require .NoError (t , err )
843
+ return nil
844
+ })
835
845
836
846
require .NoError (t , tx .Commit ())
837
847
0 commit comments