Skip to content

Commit

Permalink
Merge 1675211 into 6b635e9
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalkuo authored May 18, 2021
2 parents 6b635e9 + 1675211 commit 90fcbe7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ func TestDNSResolver(t *testing.T) {

expErr := sr(`dial tcp 127.0.0.254:HTTPBIN_PORT: connect: connection refused`)
if runtime.GOOS == "windows" {
expErr = "context deadline exceeded"
expErr = "Request timeout"
}
for name, tc := range testCases {
tc := tc
Expand Down
4 changes: 2 additions & 2 deletions js/modules/k6/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func TestRequestAndBatch(t *testing.T) {
`))
endTime := time.Now()
require.Error(t, err)
assert.Contains(t, err.Error(), "context deadline exceeded")
assert.Contains(t, err.Error(), "Request timeout")
assert.WithinDuration(t, startTime.Add(1*time.Second), endTime, 2*time.Second)

logEntry := hook.LastEntry()
Expand All @@ -344,7 +344,7 @@ func TestRequestAndBatch(t *testing.T) {
`))
endTime := time.Now()
require.Error(t, err)
assert.Contains(t, err.Error(), "context deadline exceeded")
assert.Contains(t, err.Error(), "Request timeout")
assert.WithinDuration(t, startTime.Add(1*time.Second), endTime, 2*time.Second)

logEntry := hook.LastEntry()
Expand Down
8 changes: 2 additions & 6 deletions lib/netext/httpext/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
// non specific
defaultErrorCode errCode = 1000
defaultNetNonTCPErrorCode errCode = 1010
requestTimeoutErrorCode errCode = 1050
// DNS errors
defaultDNSErrorCode errCode = 1100
dnsNoSuchHostErrorCode errCode = 1101
Expand All @@ -56,7 +57,6 @@ const (
tcpBrokenPipeErrorCode errCode = 1201
netUnknownErrnoErrorCode errCode = 1202
tcpDialErrorCode errCode = 1210
tcpDialTimeoutErrorCode errCode = 1211
tcpDialRefusedErrorCode errCode = 1212
tcpDialUnknownErrnoCode errCode = 1213
tcpResetByPeerErrorCode errCode = 1220
Expand Down Expand Up @@ -86,7 +86,6 @@ const (

const (
tcpResetByPeerErrorCodeMsg = "%s: connection reset by peer"
tcpDialTimeoutErrorCodeMsg = "dial: i/o timeout"
tcpDialRefusedErrorCodeMsg = "dial: connection refused"
tcpBrokenPipeErrorCodeMsg = "%s: broken pipe"
netUnknownErrnoErrorCodeMsg = "%s: unknown errno `%d` on %s with message `%s`"
Expand All @@ -98,6 +97,7 @@ const (
http2ConnectionErrorCodeMsg = "http2: connection error with http2 ErrCode %s"
x509HostnameErrorCodeMsg = "x509: certificate doesn't match hostname"
x509UnknownAuthority = "x509: unknown authority"
requestTimeoutErrorCodeMsg = "Request timeout"
)

func http2ErrCodeOffset(code http2.ErrCode) errCode {
Expand Down Expand Up @@ -140,10 +140,6 @@ func errorCodeForNetOpError(err *net.OpError) (errCode, string) {
}
}

// err.Op is "dial"
if err.Timeout() {
return tcpDialTimeoutErrorCode, tcpDialTimeoutErrorCodeMsg
}
if iErr, ok := err.Err.(*os.SyscallError); ok {
if errno, ok := iErr.Err.(syscall.Errno); ok {
if errno == syscall.ECONNREFUSED ||
Expand Down
2 changes: 0 additions & 2 deletions lib/netext/httpext/error_codes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func TestTCPErrors(t *testing.T) {
econnrefused = &net.OpError{Net: "tcp", Op: "dial", Err: &os.SyscallError{Err: syscall.ECONNREFUSED}}
errnounknown = &net.OpError{Net: "tcp", Op: "dial", Err: &os.SyscallError{Err: syscall.E2BIG}}
tcperror = &net.OpError{Net: "tcp", Err: errors.New("tcp error")}
timeoutedError = &net.OpError{Net: "tcp", Op: "dial", Err: timeoutError(true)}
notTimeoutedError = &net.OpError{Net: "tcp", Op: "dial", Err: timeoutError(false)}
)

Expand All @@ -141,7 +140,6 @@ func TestTCPErrors(t *testing.T) {
tcpDialUnknownErrnoCode: errnounknown,
defaultTCPErrorCode: tcperror,
tcpDialErrorCode: notTimeoutedError,
tcpDialTimeoutErrorCode: timeoutedError,
}

testMapOfErrorCodes(t, testTable)
Expand Down
5 changes: 5 additions & 0 deletions lib/netext/httpext/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package httpext

import (
"context"
"errors"
"net"
"net/http"
"net/http/httptrace"
Expand Down Expand Up @@ -243,6 +244,10 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
reqWithTracer := req.WithContext(httptrace.WithClientTrace(ctx, tracer.Trace()))
resp, err := t.state.Transport.RoundTrip(reqWithTracer)

var netError net.Error
if errors.As(err, &netError) && netError.Timeout() {
err = NewK6Error(requestTimeoutErrorCode, requestTimeoutErrorCodeMsg, netError)
}
t.saveCurrentRequest(&unfinishedRequest{
ctx: ctx,
tracer: tracer,
Expand Down

0 comments on commit 90fcbe7

Please sign in to comment.