Merge pull request #3504 from alrs/fix-brontide-test-goroutine

brontide: fix test goroutine
This commit is contained in:
Conner Fromknecht 2019-09-19 12:51:33 -07:00 committed by GitHub
commit 6585a56581
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,10 +3,10 @@ package brontide
import ( import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"fmt"
"io" "io"
"math" "math"
"net" "net"
"sync"
"testing" "testing"
"testing/iotest" "testing/iotest"
@ -266,22 +266,22 @@ func TestWriteMessageChunking(t *testing.T) {
// Launch a new goroutine to write the large message generated above in // Launch a new goroutine to write the large message generated above in
// chunks. We spawn a new goroutine because otherwise, we may block as // chunks. We spawn a new goroutine because otherwise, we may block as
// the kernel waits for the buffer to flush. // the kernel waits for the buffer to flush.
var wg sync.WaitGroup errCh := make(chan error)
wg.Add(1)
go func() { go func() {
defer wg.Done() defer close(errCh)
bytesWritten, err := localConn.Write(largeMessage) bytesWritten, err := localConn.Write(largeMessage)
if err != nil { if err != nil {
t.Fatalf("unable to write message: %v", err) errCh <- fmt.Errorf("unable to write message: %v", err)
return
} }
// The entire message should have been written out to the remote // The entire message should have been written out to the remote
// connection. // connection.
if bytesWritten != len(largeMessage) { if bytesWritten != len(largeMessage) {
t.Fatalf("bytes not fully written!") errCh <- fmt.Errorf("bytes not fully written")
return
} }
}() }()
// Attempt to read the entirety of the message generated above. // Attempt to read the entirety of the message generated above.
@ -290,7 +290,10 @@ func TestWriteMessageChunking(t *testing.T) {
t.Fatalf("unable to read message: %v", err) t.Fatalf("unable to read message: %v", err)
} }
wg.Wait() err = <-errCh
if err != nil {
t.Fatal(err)
}
// Finally, the message the remote end of the connection received // Finally, the message the remote end of the connection received
// should be identical to what we sent from the local connection. // should be identical to what we sent from the local connection.