DeadlineExceeded now implements a TimeOut() function,
since https://github.com/golang/go/commit/dc4427f3727804ded270bc6a7a8066ccb3c151d0
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 c7816c532374ad9461b78b2166922bcd21a3405f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -2,7 +2,6 @@ package plugins // import "github.com/docker/docker/pkg/plugins" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 |
- "context" |
|
| 6 | 5 |
"encoding/json" |
| 7 | 6 |
"io" |
| 8 | 7 |
"net/http" |
| ... | ... |
@@ -237,6 +236,10 @@ func TestClientSendFile(t *testing.T) {
|
| 237 | 237 |
} |
| 238 | 238 |
|
| 239 | 239 |
func TestClientWithRequestTimeout(t *testing.T) {
|
| 240 |
+ type timeoutError interface {
|
|
| 241 |
+ Timeout() bool |
|
| 242 |
+ } |
|
| 243 |
+ |
|
| 240 | 244 |
timeout := 1 * time.Millisecond |
| 241 | 245 |
testHandler := func(w http.ResponseWriter, r *http.Request) {
|
| 242 | 246 |
time.Sleep(timeout + 1*time.Millisecond) |
| ... | ... |
@@ -251,12 +254,8 @@ func TestClientWithRequestTimeout(t *testing.T) {
|
| 251 | 251 |
assert.Assert(t, is.ErrorContains(err, ""), "expected error") |
| 252 | 252 |
|
| 253 | 253 |
err = errors.Cause(err) |
| 254 |
- |
|
| 255 |
- switch e := err.(type) {
|
|
| 256 |
- case *url.Error: |
|
| 257 |
- err = e.Err |
|
| 258 |
- } |
|
| 259 |
- assert.DeepEqual(t, context.DeadlineExceeded, err) |
|
| 254 |
+ assert.ErrorType(t, err, (*timeoutError)(nil)) |
|
| 255 |
+ assert.Equal(t, err.(timeoutError).Timeout(), true) |
|
| 260 | 256 |
} |
| 261 | 257 |
|
| 262 | 258 |
type testRequestWrapper struct {
|