MCPcopy
hub / github.com/coder/websocket / TestConn

Function TestConn

conn_test.go:29–443  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestConn(t *testing.T) {
30 t.Parallel()
31
32 t.Run("fuzzData", func(t *testing.T) {
33 t.Parallel()
34
35 compressionMode := func() websocket.CompressionMode {
36 return websocket.CompressionMode(xrand.Int(int(websocket.CompressionContextTakeover) + 1))
37 }
38
39 for range 5 {
40 t.Run("", func(t *testing.T) {
41 tt, c1, c2 := newConnTest(t, &websocket.DialOptions{
42 CompressionMode: compressionMode(),
43 CompressionThreshold: xrand.Int(9999),
44 }, &websocket.AcceptOptions{
45 CompressionMode: compressionMode(),
46 CompressionThreshold: xrand.Int(9999),
47 })
48
49 tt.goEchoLoop(c2)
50
51 c1.SetReadLimit(131072)
52
53 for range 5 {
54 err := wstest.Echo(tt.ctx, c1, 131072)
55 assert.Success(t, err)
56 }
57
58 err := c1.Close(websocket.StatusNormalClosure, "")
59 assert.Success(t, err)
60 })
61 }
62 })
63
64 t.Run("badClose", func(t *testing.T) {
65 tt, c1, c2 := newConnTest(t, nil, nil)
66
67 c2.CloseRead(tt.ctx)
68
69 err := c1.Close(-1, "")
70 assert.Contains(t, err, "failed to marshal close frame: status code StatusCode(-1) cannot be set")
71 })
72
73 t.Run("ping", func(t *testing.T) {
74 tt, c1, c2 := newConnTest(t, nil, nil)
75
76 c1.CloseRead(tt.ctx)
77 c2.CloseRead(tt.ctx)
78
79 for range 10 {
80 err := c1.Ping(tt.ctx)
81 assert.Success(t, err)
82 }
83
84 err := c1.Close(websocket.StatusNormalClosure, "")
85 assert.Success(t, err)
86 })

Callers

nothing calls this directly

Calls 15

CompressionModeTypeAlias · 0.92
IntFunction · 0.92
EchoFunction · 0.92
SuccessFunction · 0.92
ContainsFunction · 0.92
EqualFunction · 0.92
BytesFunction · 0.92
NetConnFunction · 0.92
GoFunction · 0.92
StringFunction · 0.92
WriteFunction · 0.92
ReadFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…