Skip to content

Commit

Permalink
Merge 0528f80 into fa5e001
Browse files Browse the repository at this point in the history
  • Loading branch information
belak committed Apr 10, 2018
2 parents fa5e001 + 0528f80 commit 98e4570
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ type testReadWriter struct {
serverBuffer bytes.Buffer
}

func (rw *testReadWriter) maybeBroadcastEmpty() {
if rw.serverBuffer.Len() == 0 {
select {
case rw.readEmptyChan <- struct{}{}:
default:
}
}
}

func (rw *testReadWriter) Read(buf []byte) (int, error) {
if rw.queuedReadError != nil {
err := rw.queuedReadError
Expand All @@ -112,14 +121,10 @@ func (rw *testReadWriter) Read(buf []byte) (int, error) {
if err == io.EOF {
err = nil
}
rw.maybeBroadcastEmpty()
return s, err
}

select {
case rw.readEmptyChan <- struct{}{}:
default:
}

// Read from server. We're either waiting for this whole test to
// finish or for data to come in from the server buffer. We expect
// only one read to be happening at once.
Expand All @@ -130,6 +135,7 @@ func (rw *testReadWriter) Read(buf []byte) (int, error) {
if err == io.EOF {
err = nil
}
rw.maybeBroadcastEmpty()
return s, err
case <-rw.exiting:
return 0, io.EOF
Expand Down

0 comments on commit 98e4570

Please sign in to comment.