]> Cypherpunks.ru repositories - gostls13.git/commitdiff
crypto/tls: test for timeout error using the net.Error interface
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 8 Mar 2016 22:10:28 +0000 (22:10 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 8 Mar 2016 22:40:49 +0000 (22:40 +0000)
Don't do a substring search to test for a timeout error.

Fixes #14722 (maybe)

Change-Id: I4e18c749d6fd92c084a1b0b83a805119e1ae5ff2
Reviewed-on: https://go-review.googlesource.com/20403
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/crypto/tls/tls_test.go

index 27394e6d816c44718d20b6ba8228f79b3bc8d550..1a33658a1e365b9f85d432025ddd30898db95148 100644 (file)
@@ -188,11 +188,18 @@ func TestDialTimeout(t *testing.T) {
                t.Fatal("DialWithTimeout completed successfully")
        }
 
-       if !strings.Contains(err.Error(), "timed out") {
-               t.Errorf("resulting error not a timeout: %s", err)
+       if !isTimeoutError(err) {
+               t.Errorf("resulting error not a timeout: %v\nType %T: %#v", err, err, err)
        }
 }
 
+func isTimeoutError(err error) bool {
+       if ne, ok := err.(net.Error); ok {
+               return ne.Timeout()
+       }
+       return false
+}
+
 // tests that Conn.Read returns (non-zero, io.EOF) instead of
 // (non-zero, nil) when a Close (alertCloseNotify) is sitting right
 // behind the application data in the buffer.