1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Harden TestClientWithRequestTimeout

DeadlineExceeded now implements a TimeOut() function,
since dc4427f372

Check for this interface, to prevent possibly incorrect failures;

```
00:16:41 --- FAIL: TestClientWithRequestTimeout (0.00s)
00:16:41     client_test.go:259: assertion failed:
00:16:41         --- context.DeadlineExceeded
00:16:41         +++ err
00:16:41         :
00:16:41         	-: context.deadlineExceededError{}
00:16:41         	+: &net.OpError{Op: "dial", Net: "tcp", Addr: s"127.0.0.1:49294", Err: &poll.TimeoutError{}}
00:16:41
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit c7816c5323)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-04-18 11:59:25 +02:00
parent 56784591bf
commit a02539b3e8
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -2,7 +2,6 @@ package plugins // import "github.com/docker/docker/pkg/plugins"
import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
@ -237,6 +236,10 @@ func TestClientSendFile(t *testing.T) {
}
func TestClientWithRequestTimeout(t *testing.T) {
type timeoutError interface {
Timeout() bool
}
timeout := 1 * time.Millisecond
testHandler := func(w http.ResponseWriter, r *http.Request) {
time.Sleep(timeout + 1*time.Millisecond)
@ -251,12 +254,8 @@ func TestClientWithRequestTimeout(t *testing.T) {
assert.Assert(t, is.ErrorContains(err, ""), "expected error")
err = errors.Cause(err)
switch e := err.(type) {
case *url.Error:
err = e.Err
}
assert.DeepEqual(t, context.DeadlineExceeded, err)
assert.ErrorType(t, err, (*timeoutError)(nil))
assert.Equal(t, err.(timeoutError).Timeout(), true)
}
type testRequestWrapper struct {