MCPcopy
hub / github.com/gorilla/websocket / TestWriteBufferPoolSync

Function TestWriteBufferPoolSync

conn_test.go:281–300  ·  view source on GitHub ↗

TestWriteBufferPoolSync ensures that *sync.Pool works as a buffer pool.

(t *testing.T)

Source from the content-addressed store, hash-verified

279
280// TestWriteBufferPoolSync ensures that *sync.Pool works as a buffer pool.
281func TestWriteBufferPoolSync(t *testing.T) {
282 var buf bytes.Buffer
283 var pool sync.Pool
284 wc := newConn(fakeNetConn{Writer: &buf}, true, 1024, 1024, &pool, nil, nil)
285 rc := newTestConn(&buf, nil, false)
286
287 const message = "Hello World!"
288 for i := 0; i < 3; i++ {
289 if err := wc.WriteMessage(TextMessage, []byte(message)); err != nil {
290 t.Fatalf("wc.WriteMessage() returned %v", err)
291 }
292 opCode, p, err := rc.ReadMessage()
293 if opCode != TextMessage || err != nil {
294 t.Fatalf("ReadMessage() returned %d, p, %v", opCode, err)
295 }
296 if s := string(p); s != message {
297 t.Fatalf("message is %s, want %s", s, message)
298 }
299 }
300}
301
302// errorWriter is an io.Writer than returns an error on all writes.
303type errorWriter struct{}

Callers

nothing calls this directly

Calls 4

newConnFunction · 0.85
newTestConnFunction · 0.85
WriteMessageMethod · 0.80
ReadMessageMethod · 0.80

Tested by

no test coverage detected