aboutsummaryrefslogtreecommitdiff
path: root/ssh/test
diff options
context:
space:
mode:
authorLars Lehtonen <lars.lehtonen@gmail.com>2019-11-15 14:31:24 -0800
committerBrad Fitzpatrick <bradfitz@golang.org>2019-11-17 06:32:00 +0000
commit497ca9f6d64f9bb73048a960b4098309edcd2205 (patch)
tree854eaa80096b0ebf9ff5209f5bf13b808048d5c2 /ssh/test
parente1110fd1c708ef015366ea01799a23c459593c47 (diff)
downloadgo-x-crypto-497ca9f6d64f9bb73048a960b4098309edcd2205.tar.xz
ssh/test: fix test goroutine error handling
Adds an error channel to the test helper function testPortForward() to collect errors that happen inside a goroutine. Change-Id: I6db1d24b935fdfad637c971581ae80beaebd8a1f Reviewed-on: https://go-review.googlesource.com/c/crypto/+/207462 Run-TryBot: Han-Wen Nienhuys <hanwen@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'ssh/test')
-rw-r--r--ssh/test/forward_unix_test.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/ssh/test/forward_unix_test.go b/ssh/test/forward_unix_test.go
index 2f5669a..4c44e57 100644
--- a/ssh/test/forward_unix_test.go
+++ b/ssh/test/forward_unix_test.go
@@ -8,6 +8,7 @@ package test
import (
"bytes"
+ "fmt"
"io"
"io/ioutil"
"math/rand"
@@ -31,17 +32,21 @@ func testPortForward(t *testing.T, n, listenAddr string) {
t.Fatal(err)
}
+ errCh := make(chan error, 1)
+
go func() {
+ defer close(errCh)
sshConn, err := sshListener.Accept()
if err != nil {
- t.Fatalf("listen.Accept failed: %v", err)
+ errCh <- fmt.Errorf("listen.Accept failed: %v", err)
+ return
}
+ defer sshConn.Close()
_, err = io.Copy(sshConn, sshConn)
if err != nil && err != io.EOF {
- t.Fatalf("ssh client copy: %v", err)
+ errCh <- fmt.Errorf("ssh client copy: %v", err)
}
- sshConn.Close()
}()
forwardedAddr := sshListener.Addr().String()
@@ -76,6 +81,12 @@ func testPortForward(t *testing.T, n, listenAddr string) {
t.Errorf("netConn.CloseWrite: %v", err)
}
+ // Check for errors on server goroutine
+ err = <-errCh
+ if err != nil {
+ t.Fatalf("server: %v", err)
+ }
+
read := <-readChan
if len(sent) != len(read) {