]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/tls: add timeouts to recorded tests
authorFilippo Valsorda <filippo@golang.org>
Thu, 25 Oct 2018 01:31:18 +0000 (21:31 -0400)
committerFilippo Valsorda <filippo@golang.org>
Thu, 25 Oct 2018 19:02:40 +0000 (19:02 +0000)
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 <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
src/crypto/tls/handshake_client_test.go
src/crypto/tls/handshake_server_test.go

index dcd69140984d3905d2f90e4a3cf0a6834c9cba58..5a1e608536966d431199c21b97218b5e004baa54 100644 (file)
@@ -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)
index 44c67ed0638991cd41d20bd9af3e49d312d517e4..2a77584cddd21d27d14b46815b1dcf3eaa373a49 100644 (file)
@@ -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)