Fix race condition in TestServerClose (#75)

In test server close, 3 things need to happen in order:

- Client session start
- Server.Close
- Client session exit (With io.EOF)

This fix ensures the client won't do anything until after the call to
close which ensure's we'll get io.EOF rather than a different error.
This commit is contained in:
Kaleb Elwert 2018-04-16 18:00:03 -07:00 committed by Jeff Lindsay
parent ef66069ab6
commit 8ba78c2f83

@ -73,11 +73,14 @@ func TestServerClose(t *testing.T) {
}
}()
doneCh := make(chan struct{})
clientDoneChan := make(chan struct{})
closeDoneChan := make(chan struct{})
sess, _, cleanup := newClientSession(t, l.Addr().String(), nil)
go func() {
defer cleanup()
defer close(doneCh)
defer close(clientDoneChan)
<-closeDoneChan
if err := sess.Run(""); err != nil && err != io.EOF {
t.Fatal(err)
}
@ -88,6 +91,7 @@ func TestServerClose(t *testing.T) {
if err != nil {
t.Fatal(err)
}
close(closeDoneChan)
}()
timeout := time.After(100 * time.Millisecond)
@ -96,7 +100,7 @@ func TestServerClose(t *testing.T) {
t.Error("timeout")
return
case <-s.getDoneChan():
<-doneCh
<-clientDoneChan
return
}
}