Merge pull request #7119 from hashicorp/fix_race

try to remove race condition in mux test
This commit is contained in:
Adrien Delorme 2018-12-17 11:42:55 +01:00 committed by GitHub
commit 895d49ca10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package rpc package rpc
import ( import (
"fmt"
"net" "net"
"testing" "testing"
@ -17,14 +18,17 @@ func TestMuxBroker(t *testing.T) {
go bc.Run() go bc.Run()
go bs.Run() go bs.Run()
errChan := make(chan error, 2)
go func() { go func() {
defer close(errChan)
c, err := bc.Dial(5) c, err := bc.Dial(5)
if err != nil { if err != nil {
t.Fatalf("err: %s", err) errChan <- fmt.Errorf("err dialing: %s", err.Error())
return
} }
if _, err := c.Write([]byte{42}); err != nil { if _, err := c.Write([]byte{42}); err != nil {
t.Fatalf("err: %s", err) errChan <- fmt.Errorf("err writing: %s", err.Error())
} }
}() }()
@ -41,6 +45,12 @@ func TestMuxBroker(t *testing.T) {
if data[0] != 42 { if data[0] != 42 {
t.Fatalf("bad: %d", data[0]) t.Fatalf("bad: %d", data[0])
} }
for err := range errChan {
if err != nil {
t.Fatalf(err.Error())
}
}
} }
func testYamux(t *testing.T) (client *yamux.Session, server *yamux.Session) { func testYamux(t *testing.T) (client *yamux.Session, server *yamux.Session) {