From eb77666646b7df6f296f79c0c5367061b1c75d71 Mon Sep 17 00:00:00 2001 From: Alex Barganier Date: Thu, 28 Mar 2024 14:32:29 -0400 Subject: [PATCH] pkg/sql/sqlstats: de-flake TestTransactionInsightsFailOnCommit Fixes: https://github.com/cockroachdb/cockroach/issues/117061 TestTransactionInsightsFailOnCommit runs two transactions, one of which is expected to fail on commit due to an isolation error as it interacts with the other transaction. We query crdb_internal.node_txn_execution_insights, which queries the in-memory insights data, to check that a txn insight was generated for the failed txn with a `FailedExecution` insight. However, when querying the crdb_internal table, the query is too broad. In the test, the successful transaction can still possibly generate a `SlowExecution` insight. In this case, when looking for the `FailedExecution` insight, we were instead getting an insight from the successful transaction. The fix is to narrow the SELECT criteria to ensure we're selecting the correct insight. The fix also expands the failed assertion logging. Release note: none --- pkg/sql/sqlstats/insights/integration/insights_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/sql/sqlstats/insights/integration/insights_test.go b/pkg/sql/sqlstats/insights/integration/insights_test.go index 04c6ae6a4791..35b70ab447c8 100644 --- a/pkg/sql/sqlstats/insights/integration/insights_test.go +++ b/pkg/sql/sqlstats/insights/integration/insights_test.go @@ -490,12 +490,16 @@ SELECT query, COALESCE(last_error_code, '') last_error_code, COALESCE(last_error_redactable, '') last_error FROM crdb_internal.node_txn_execution_insights -WHERE app_name = $1`, appName) +WHERE app_name = $1 +AND query = 'SELECT * FROM myusers WHERE city = _ ; UPDATE myusers SET name = _ WHERE city = _'`, appName) return row.Scan(&query, &problems, &status, &errorCode, &errorMsg) }) - require.Equal(t, "SELECT * FROM myusers WHERE city = _ ; UPDATE myusers SET name = _ WHERE city = _", query) + require.Equalf(t, + "SELECT * FROM myusers WHERE city = _ ; UPDATE myusers SET name = _ WHERE city = _", query, + "unexpected txn insight found - query: %s, problems: %s, status: %s, errCode: %s, errMsg: %s", + query, problems, status, errorCode, errorMsg) expectedProblem := "{FailedExecution}" replacedSlowProblems := problems if problems != expectedProblem {