Skip to content

Commit d07fe80

Browse files
committed
integration: fix flaky TestInsightsIntegrationForContention
This test has been seen to flake recently, due to the query on crdb_internal.node_transactions not returning any rows. To fix, it is now run within a testutils.SucceedSoon and will retry until it exists. Fixes: #151125, #150555, #150139 Release note: None
1 parent 53ce6cb commit d07fe80

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pkg/sql/sqlstats/insights/integration/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ go_test(
2626
"//pkg/util/log",
2727
"//pkg/util/timeutil",
2828
"//pkg/util/uuid",
29+
"@com_github_cockroachdb_errors//:errors",
2930
"@com_github_stretchr_testify//require",
3031
],
3132
)

pkg/sql/sqlstats/insights/integration/insights_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/cockroachdb/cockroach/pkg/util/log"
3939
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
4040
"github.com/cockroachdb/cockroach/pkg/util/uuid"
41+
"github.com/cockroachdb/errors"
4142
"github.com/stretchr/testify/require"
4243
)
4344

@@ -803,7 +804,6 @@ func TestInsightsIntegrationForContention(t *testing.T) {
803804
// Chan to wait for the txn to complete to avoid checking for insights before the txn is committed.
804805
txnDoneChan := make(chan struct{})
805806

806-
observerConn := sqlutils.MakeSQLRunner(tc.ApplicationLayer(0).SQLConn(t))
807807
txConn := sqlutils.MakeSQLRunner(tc.ApplicationLayer(0).SQLConn(t))
808808
tx := txConn.Begin(t)
809809

@@ -828,10 +828,20 @@ func TestInsightsIntegrationForContention(t *testing.T) {
828828
require.NoError(t, errTxn)
829829

830830
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
833833
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+
})
835845

836846
require.NoError(t, tx.Commit())
837847

0 commit comments

Comments
 (0)