Skip to content

Commit

Permalink
Readd dial timeout error code and a test
Browse files Browse the repository at this point in the history
This was dropped as part of #2008 but it will be better if we
differentiate between different timeouts

Also add test for the `request timeout` error code in `httpext`
  • Loading branch information
mstoykov committed May 21, 2021
1 parent 244218d commit 01a5239
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/netext/httpext/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ 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,6 +87,7 @@ 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 Down
3 changes: 2 additions & 1 deletion lib/netext/httpext/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ func TestURL(t *testing.T) {
})
}

func TestMakeRequestTimeout(t *testing.T) {
func TestMakeRequestTimeoutInTheMiddle(t *testing.T) {
t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Length", "100000")
w.WriteHeader(200)
Expand Down
8 changes: 7 additions & 1 deletion lib/netext/httpext/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,14 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {

var netError net.Error
if errors.As(err, &netError) && netError.Timeout() {
err = NewK6Error(requestTimeoutErrorCode, requestTimeoutErrorCodeMsg, netError)
var netOpError *net.OpError
if errors.As(err, &netOpError) && netOpError.Op == "dial" {
err = NewK6Error(tcpDialTimeoutErrorCode, tcpDialTimeoutErrorCodeMsg, netError)
} else {
err = NewK6Error(requestTimeoutErrorCode, requestTimeoutErrorCodeMsg, netError)
}
}

t.saveCurrentRequest(&unfinishedRequest{
ctx: ctx,
tracer: tracer,
Expand Down

0 comments on commit 01a5239

Please sign in to comment.