proxy_test: Fix a goroutine-leak bug in testHTTPConnect: now use channel done to store err and call t.Fatalf when err not nil (#3080)

This commit is contained in:
lzhfromustc 2019-10-09 13:12:01 -04:00 коммит произвёл Easwar Swaminathan
Родитель 2d6a3edc72
Коммит ff0c603b9b
1 изменённых файлов: 6 добавлений и 4 удалений

Просмотреть файл

@ -119,16 +119,16 @@ func testHTTPConnect(t *testing.T, proxyURLModify func(*url.URL) *url.URL, proxy
msg := []byte{4, 3, 5, 2}
recvBuf := make([]byte, len(msg))
done := make(chan struct{})
done := make(chan error)
go func() {
in, err := blis.Accept()
if err != nil {
t.Errorf("failed to accept: %v", err)
done <- err
return
}
defer in.Close()
in.Read(recvBuf)
close(done)
done <- nil
}()
// Overwrite the function in the test and restore them in defer.
@ -154,7 +154,9 @@ func testHTTPConnect(t *testing.T, proxyURLModify func(*url.URL) *url.URL, proxy
// Send msg on the connection.
c.Write(msg)
<-done
if err := <-done; err != nil {
t.Fatalf("failed to accept: %v", err)
}
// Check received msg.
if string(recvBuf) != string(msg) {