[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [meek/utls_2] Don't panic in test goroutines.



commit 00b92d3c5e8e2008a5ea1f0667d229e6bbeddc8d
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Wed Feb 6 01:51:23 2019 -0700

    Don't panic in test goroutines.
    
    panic means the channel won't close, which means the parent goroutine
    will hang. Also take the opportunity to log an error message.
---
 meek-client/proxy_test.go | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/meek-client/proxy_test.go b/meek-client/proxy_test.go
index 0b37fb3..820f580 100644
--- a/meek-client/proxy_test.go
+++ b/meek-client/proxy_test.go
@@ -75,7 +75,7 @@ func TestAddrForDial(t *testing.T) {
 
 // Dial the given address with the given proxy, and return the http.Request that
 // the proxy server would have received.
-func requestResultingFromDial(ln net.Listener, makeProxy func(addr net.Addr) (*httpProxy, error), network, addr string) (*http.Request, error) {
+func requestResultingFromDial(t *testing.T, ln net.Listener, makeProxy func(addr net.Addr) (*httpProxy, error), network, addr string) (*http.Request, error) {
 	ch := make(chan *http.Request, 1)
 
 	go func() {
@@ -84,13 +84,15 @@ func requestResultingFromDial(ln net.Listener, makeProxy func(addr net.Addr) (*h
 		}()
 		conn, err := ln.Accept()
 		if err != nil {
-			panic(err)
+			t.Error(err)
+			return
 		}
 		defer conn.Close()
 		br := bufio.NewReader(conn)
 		req, err := http.ReadRequest(br)
 		if err != nil {
-			panic(err)
+			t.Error(err)
+			return
 		}
 		ch <- req
 	}()
@@ -105,18 +107,18 @@ func requestResultingFromDial(ln net.Listener, makeProxy func(addr net.Addr) (*h
 	return <-ch, nil
 }
 
-func requestResultingFromDialHTTP(makeProxy func(addr net.Addr) (*httpProxy, error), network, addr string) (*http.Request, error) {
+func requestResultingFromDialHTTP(t *testing.T, makeProxy func(addr net.Addr) (*httpProxy, error), network, addr string) (*http.Request, error) {
 	ln, err := net.Listen("tcp", "127.0.0.1:0")
 	if err != nil {
 		return nil, err
 	}
 	defer ln.Close()
-	return requestResultingFromDial(ln, makeProxy, network, addr)
+	return requestResultingFromDial(t, ln, makeProxy, network, addr)
 }
 
 // Test that the HTTP proxy client sends a correct request.
 func TestProxyHTTPCONNECT(t *testing.T) {
-	req, err := requestResultingFromDialHTTP(func(addr net.Addr) (*httpProxy, error) {
+	req, err := requestResultingFromDialHTTP(t, func(addr net.Addr) (*httpProxy, error) {
 		return ProxyHTTP("tcp", addr.String(), nil, proxy.Direct)
 	}, "tcp", testAddr)
 	if err != nil {
@@ -139,7 +141,7 @@ func TestProxyHTTPProxyAuthorization(t *testing.T) {
 		User:     testUsername,
 		Password: testPassword,
 	}
-	req, err := requestResultingFromDialHTTP(func(addr net.Addr) (*httpProxy, error) {
+	req, err := requestResultingFromDialHTTP(t, func(addr net.Addr) (*httpProxy, error) {
 		return ProxyHTTP("tcp", addr.String(), auth, proxy.Direct)
 	}, "tcp", testAddr)
 	if err != nil {
@@ -169,7 +171,7 @@ func TestProxyHTTPProxyAuthorization(t *testing.T) {
 	}
 }
 
-func requestResultingFromDialHTTPS(makeProxy func(addr net.Addr) (*httpProxy, error), network, addr string) (*http.Request, error) {
+func requestResultingFromDialHTTPS(t *testing.T, makeProxy func(addr net.Addr) (*httpProxy, error), network, addr string) (*http.Request, error) {
 	// Create a TLS listener using a temporary self-signed certificate.
 	// https://golang.org/src/crypto/tls/generate_cert.go
 	priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
@@ -210,11 +212,11 @@ func requestResultingFromDialHTTPS(makeProxy func(addr net.Addr) (*httpProxy, er
 		return nil, err
 	}
 	defer ln.Close()
-	return requestResultingFromDial(ln, makeProxy, network, addr)
+	return requestResultingFromDial(t, ln, makeProxy, network, addr)
 }
 
 func TestProxyHTTPSCONNECT(t *testing.T) {
-	req, err := requestResultingFromDialHTTPS(func(addr net.Addr) (*httpProxy, error) {
+	req, err := requestResultingFromDialHTTPS(t, func(addr net.Addr) (*httpProxy, error) {
 		return ProxyHTTPS("tcp", addr.String(), nil, proxy.Direct, &utls.Config{InsecureSkipVerify: true}, &utls.HelloFirefox_Auto)
 	}, "tcp", testAddr)
 	if err != nil {



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits