brontide: fix goroutine in test
This commit is contained in:
parent
1dbb653b3a
commit
4d4da3c07c
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user