Skip to content

Commit 11af7f8

Browse files
committed
netconn: Add test for disabled read limit
1 parent ea87744 commit 11af7f8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: conn_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,37 @@ func TestConn(t *testing.T) {
208208
}
209209
})
210210

211+
t.Run("netConn/readLimit", func(t *testing.T) {
212+
tt, c1, c2 := newConnTest(t, nil, nil)
213+
214+
n1 := websocket.NetConn(tt.ctx, c1, websocket.MessageBinary)
215+
n2 := websocket.NetConn(tt.ctx, c2, websocket.MessageBinary)
216+
217+
s := strings.Repeat("papa", 1 << 20)
218+
errs := xsync.Go(func() error {
219+
_, err := n2.Write([]byte(s))
220+
if err != nil {
221+
return err
222+
}
223+
return n2.Close()
224+
})
225+
226+
b, err := ioutil.ReadAll(n1)
227+
assert.Success(t, err)
228+
229+
_, err = n1.Read(nil)
230+
assert.Equal(t, "read error", err, io.EOF)
231+
232+
select {
233+
case err := <-errs:
234+
assert.Success(t, err)
235+
case <-tt.ctx.Done():
236+
t.Fatal(tt.ctx.Err())
237+
}
238+
239+
assert.Equal(t, "read msg", s, string(b))
240+
})
241+
211242
t.Run("wsjson", func(t *testing.T) {
212243
tt, c1, c2 := newConnTest(t, nil, nil)
213244

0 commit comments

Comments
 (0)