Fix: conn_bytelimit_test

This commit is contained in:
kayos@tcp.direct 2022-11-11 05:10:37 -08:00
orang tua 369eed2daa
melakukan 91e8cb4586
Ditandai oleh: kayos
GPG Key ID: 4B841471B4BEE979
2 mengubah file dengan 10 tambahan dan 4 penghapusan

Melihat File

@ -296,6 +296,10 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.
if d.Timeout != 0 {
ctx, cancel = context.WithTimeout(ctx, d.Timeout)
}
go func() {
<-ctx.Done()
cancel()
}()
// ensure that our aux dialer is up-to-date; copied from http/transport.go
d.Dialer.Timeout = d.getTimeout(d.ConnectTimeout)
d.Dialer.KeepAlive = d.Timeout
@ -306,7 +310,6 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.
dialContext, cancelDial := context.WithTimeout(ctx, d.Dialer.Timeout)
defer func() {
cancelDial()
cancel()
}()
conn, err := d.Dialer.DialContext(dialContext, network, address)
if err != nil {

Melihat File

@ -123,7 +123,7 @@ func checkedSendReceive(t *testing.T, conn *TimeoutConnection, size int) (result
ret, err := sendReceive(t, conn, size)
if err != nil {
if !overflowed {
if !overflowed && !errors.Is(err, io.EOF) {
// If there is no overflow, there should be no error
return tErrorf("read: unexpected error: %v", err)
}
@ -131,7 +131,7 @@ func checkedSendReceive(t *testing.T, conn *TimeoutConnection, size int) (result
// EOF and ErrReadLimitExceeded are the only errors that should be returned
return tErrorf("read: wrong error: %v", err)
}
if !errors.Is(err, io.EOF) && action != ReadLimitExceededActionTruncate {
if errors.Is(err, io.EOF) && action != ReadLimitExceededActionTruncate {
// EOF should only occur with truncation
return tErrorf("read: unexpected EOF")
}
@ -342,6 +342,10 @@ func runBytesReadLimitTrial(t *testing.T, connector timeoutConnector, idx int, m
t.Helper()
cfg := connector.getConfig()
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-ctx.Done()
cancel()
}()
port := 0x1235 + idx
runEchoServer(t, port)
conn, err := connector.connect(ctx, t, port, idx)
@ -360,7 +364,6 @@ func runBytesReadLimitTrial(t *testing.T, connector timeoutConnector, idx int, m
result = fmt.Errorf("BytesRead(%d) != expected(%d)", conn.BytesRead, expectedSize)
t.Error(result)
}
cancel()
}()
return method(cfg, t, conn, idx)
}