From a7fb5e1bd2d655c275fdf513fe0ea7ea7517e675 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Wed, 24 Oct 2018 21:31:18 -0400 Subject: [PATCH] crypto/tls: add timeouts to recorded tests If something causes the recorded tests to deviate from the expected flows, they might wait forever for data that is not coming. Add a short timeout, after which a useful error message is shown. Change-Id: Ib11ccc0e17dcb8b2180493556017275678abbb08 Reviewed-on: https://go-review.googlesource.com/c/144116 Run-TryBot: Filippo Valsorda TryBot-Result: Gobot Gobot Reviewed-by: Adam Langley --- src/crypto/tls/handshake_client_test.go | 2 ++ src/crypto/tls/handshake_server_test.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/crypto/tls/handshake_client_test.go b/src/crypto/tls/handshake_client_test.go index dcd69140984..5a1e6085369 100644 --- a/src/crypto/tls/handshake_client_test.go +++ b/src/crypto/tls/handshake_client_test.go @@ -384,10 +384,12 @@ func (test *clientTest) run(t *testing.T, write bool) { } for i, b := range flows { if i%2 == 1 { + serverConn.SetWriteDeadline(time.Now().Add(1 * time.Second)) serverConn.Write(b) continue } bb := make([]byte, len(b)) + serverConn.SetReadDeadline(time.Now().Add(1 * time.Second)) _, err := io.ReadFull(serverConn, bb) if err != nil { t.Fatalf("%s #%d: %s", test.name, i, err) diff --git a/src/crypto/tls/handshake_server_test.go b/src/crypto/tls/handshake_server_test.go index 44c67ed0638..2a77584cddd 100644 --- a/src/crypto/tls/handshake_server_test.go +++ b/src/crypto/tls/handshake_server_test.go @@ -615,10 +615,12 @@ func (test *serverTest) run(t *testing.T, write bool) { } for i, b := range flows { if i%2 == 0 { + clientConn.SetWriteDeadline(time.Now().Add(1 * time.Second)) clientConn.Write(b) continue } bb := make([]byte, len(b)) + clientConn.SetReadDeadline(time.Now().Add(1 * time.Second)) n, err := io.ReadFull(clientConn, bb) if err != nil { t.Fatalf("%s #%d: %s\nRead %d, wanted %d, got %x, wanted %x\n", test.name, i+1, err, n, len(bb), bb[:n], b)