Skip to content

Commit

Permalink
kv: fix assertion in TestProxyTracing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nvanbenschoten committed Oct 28, 2024
1 parent 3b5f67a commit ade2d9b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pkg/kv/kvclient/kvcoord/dist_sender_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package kvcoord_test
import (
"bytes"
"context"
gosql "database/sql"
"fmt"
"reflect"
"sort"
Expand Down Expand Up @@ -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)
}

0 comments on commit ade2d9b

Please sign in to comment.