From ade2d9bd2969c7212006e2797618c64601f52c07 Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Mon, 28 Oct 2024 17:27:25 -0400 Subject: [PATCH] kv: fix assertion in TestProxyTracing This commit fixes the assertion in TestProxyTracing so that the test will fail if request proxying is not working as expected. The test was fooling itself, expecting QueryRowContext to return a nil Row if no matching trace event was found. This is not the case, as a nil Row is never returned. Instead, Row.Scan returns ErrNoRows if no matching row is found. Also, the query wasn't even running because it was passing the last line of the query string in as a parameter, leading to the error: "pq: got 1 parameters but the statement requires 0". I confirmed that before this change, the test passes even with request proxying disabled. After this change, the test fails. Epic: None Release note: None --- .../kvcoord/dist_sender_server_test.go | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/kv/kvclient/kvcoord/dist_sender_server_test.go b/pkg/kv/kvclient/kvcoord/dist_sender_server_test.go index 8a0d38151122..c38c36264fe6 100644 --- a/pkg/kv/kvclient/kvcoord/dist_sender_server_test.go +++ b/pkg/kv/kvclient/kvcoord/dist_sender_server_test.go @@ -8,6 +8,7 @@ package kvcoord_test import ( "bytes" "context" + gosql "database/sql" "fmt" "reflect" "sort" @@ -4898,11 +4899,17 @@ func TestProxyTracing(t *testing.T) { // Expect the "proxy request complete" message to be in the trace and that it // comes from the proxy node n2. - row := conn.QueryRowContext(ctx, "SELECT message, tag, location "+ - "FROM [SHOW TRACE FOR SESSION] "+ - "WHERE message LIKE '%proxy request complete%'"+ - "AND location LIKE '%server/node%'", - "AND tag LIKE '%n2%'", - ) - require.NotNil(t, row) + var msg, tag, loc string + if err = conn.QueryRowContext(ctx, `SELECT message, tag, location + FROM [SHOW TRACE FOR SESSION] + WHERE message LIKE '%proxy request complete%' + AND location LIKE '%server/node%' + AND tag LIKE '%n2%'`, + ).Scan(&msg, &tag, &loc); err != nil { + if errors.Is(err, gosql.ErrNoRows) { + t.Fatalf("request succeeded without proxying") + } + t.Fatal(err) + } + t.Logf("found trace event; msg=%s, tag=%s, loc=%s", msg, tag, loc) }