Test truncated frames at all positions

This commit is contained in:
Gary Burd 2016-04-25 08:42:53 -07:00
parent ae46df13e9
commit a724ba4528
1 changed files with 27 additions and 19 deletions

View File

@ -175,8 +175,9 @@ func TestCloseBeforeFinalFrame(t *testing.T) {
}
func TestEOFWithinFrame(t *testing.T) {
const bufSize = 512
const bufSize = 64
for n := 0; ; n++ {
var b bytes.Buffer
wc := newConn(fakeNetConn{Reader: nil, Writer: &b}, false, 1024, 1024)
rc := newConn(fakeNetConn{Reader: &b, Writer: nil}, true, 1024, 1024)
@ -185,19 +186,26 @@ func TestEOFWithinFrame(t *testing.T) {
w.Write(make([]byte, bufSize))
w.Close()
b.Truncate(bufSize / 2)
if n >= b.Len() {
break
}
b.Truncate(n)
op, r, err := rc.NextReader()
if err == errUnexpectedEOF {
continue
}
if op != BinaryMessage || err != nil {
t.Fatalf("NextReader() returned %d, %v", op, err)
t.Fatalf("%d: NextReader() returned %d, %v", n, op, err)
}
_, err = io.Copy(ioutil.Discard, r)
if err != errUnexpectedEOF {
t.Fatalf("io.Copy() returned %v, want %v", err, errUnexpectedEOF)
t.Fatalf("%d: io.Copy() returned %v, want %v", n, err, errUnexpectedEOF)
}
_, _, err = rc.NextReader()
if err != errUnexpectedEOF {
t.Fatalf("NextReader() returned %v, want %v", err, errUnexpectedEOF)
t.Fatalf("%d: NextReader() returned %v, want %v", n, err, errUnexpectedEOF)
}
}
}