mirror of https://github.com/cbeuw/Cloak
Fix a timing sensitive test on reading data after actively closing a stream
This commit is contained in:
parent
ff503b06a8
commit
fd5005db0a
|
|
@ -151,6 +151,16 @@ func TestStream_Close(t *testing.T) {
|
||||||
t.Error("failed to accept stream", err)
|
t.Error("failed to accept stream", err)
|
||||||
return
|
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()
|
err = stream.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("failed to actively close stream", err)
|
t.Error("failed to actively close stream", err)
|
||||||
|
|
@ -162,8 +172,7 @@ func TestStream_Close(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
readBuf := make([]byte, len(testPayload))
|
_, err = io.ReadFull(stream, readBuf[1:])
|
||||||
_, err = io.ReadFull(stream, readBuf)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("can't read residual data %v", err)
|
t.Errorf("can't read residual data %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue