From: Brad Fitzpatrick Date: Tue, 8 Mar 2016 22:10:28 +0000 (+0000) Subject: crypto/tls: test for timeout error using the net.Error interface X-Git-Tag: go1.7beta1~1467 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bf44c4c889935b3ef1db9b7fd0a14ce4e5508cab;p=gostls13.git crypto/tls: test for timeout error using the net.Error interface 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 Reviewed-by: Keith Randall TryBot-Result: Gobot Gobot --- diff --git a/src/crypto/tls/tls_test.go b/src/crypto/tls/tls_test.go index 27394e6d81..1a33658a1e 100644 --- a/src/crypto/tls/tls_test.go +++ b/src/crypto/tls/tls_test.go @@ -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.