Skip to content

Commit 63a324a

Browse files
rickystewartrafiss
authored andcommitted
pgwire: increase timeout and add Error() call
This test seems to deadlock sporadically under remote execution. I believe the connection is timing out, which due to the way this test was written causes it to deadlock. I'm increasing the timeout to attempt to increase reliability, and separately, we also add a call to `Error()` to mark the test as failed should the connection fail. Additionally, getSessionArgs was updated to return a fake pgwire connection handshake response, so that the test could assert that the connection succeeded. Closes #118741. Epic: None Release note: None
1 parent 2531de8 commit 63a324a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

pkg/sql/pgwire/conn_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,10 +1626,12 @@ func TestParseClientProvidedSessionParameters(t *testing.T) {
16261626
t.Run(tc.desc, func(t *testing.T) {
16271627

16281628
var netConn net.Conn
1629-
wg := sync.WaitGroup{}
1630-
wg.Add(1)
1629+
clientDone := sync.WaitGroup{}
1630+
clientDone.Add(1)
1631+
serverReceivedConn := sync.WaitGroup{}
1632+
serverReceivedConn.Add(1)
16311633
go func(query string) {
1632-
defer wg.Done()
1634+
defer clientDone.Done()
16331635
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
16341636
defer cancel()
16351637
url := fmt.Sprintf("%s&%s", baseURL, query)
@@ -1641,6 +1643,7 @@ func TestParseClientProvidedSessionParameters(t *testing.T) {
16411643
// ignore the error because there is no answer from the server, we are
16421644
// interested in parsing session arguments only. We close the connection
16431645
// immediately, since getSessionArgs is blocking.
1646+
serverReceivedConn.Wait()
16441647
_ = netConn.Close()
16451648
_ = c.Close(ctx)
16461649

@@ -1652,10 +1655,15 @@ func TestParseClientProvidedSessionParameters(t *testing.T) {
16521655
t.Error("pgconn asyncClose did not clean up on time")
16531656
}
16541657
}(tc.query)
1655-
// Wait for the client to connect and perform the handshake.
1658+
// Wait for the client to connect and perform the handshake. Use a
1659+
// closure so that the WaitGroup is marked as done even if there's a
1660+
// panic.
16561661
var args sql.SessionArgs
1657-
netConn, args, err = getSessionArgs(ln, true /* trustRemoteAddr */)
1658-
wg.Wait()
1662+
func() {
1663+
defer serverReceivedConn.Done()
1664+
netConn, args, err = getSessionArgs(ln, true /* trustRemoteAddr */)
1665+
}()
1666+
clientDone.Wait()
16591667
tc.assert(t, args, err)
16601668
})
16611669
}

0 commit comments

Comments
 (0)