Fix a timing sensitive test on reading data after actively closing a stream

This commit is contained in:
Andy Wang 2020-12-22 20:16:47 +00:00
parent ff503b06a8
commit fd5005db0a
No known key found for this signature in database
GPG Key ID: 181B49F9F38F3374
1 changed files with 11 additions and 2 deletions

View File

@ -151,6 +151,16 @@ func TestStream_Close(t *testing.T) {
t.Error("failed to accept stream", err)
return
}
// we read something to wait for the test frame to reach our recvBuffer.
// if it's empty by the point we call stream.Close(), the incoming
// frame will be dropped
readBuf := make([]byte, len(testPayload))
_, err = io.ReadFull(stream, readBuf[:1])
if err != nil {
t.Errorf("can't read any data before active closing")
}
err = stream.Close()
if err != nil {
t.Error("failed to actively close stream", err)
@ -162,8 +172,7 @@ func TestStream_Close(t *testing.T) {
return
}
readBuf := make([]byte, len(testPayload))
_, err = io.ReadFull(stream, readBuf)
_, err = io.ReadFull(stream, readBuf[1:])
if err != nil {
t.Errorf("can't read residual data %v", err)
}