MCPcopy Create free account
hub / github.com/Shopify/goose / TestBufferGrowth

Function TestBufferGrowth

syncio/buffer_test.go:572–590  ·  view source on GitHub ↗

Tests that we occasionally compact. Issue 5154.

(t *testing.T)

Source from the content-addressed store, hash-verified

570
571// Tests that we occasionally compact. Issue 5154.
572func TestBufferGrowth(t *testing.T) {
573 var b Buffer
574 buf := make([]byte, 1024)
575 b.Write(buf[0:1])
576 var cap0 int
577 for i := 0; i < 5<<10; i++ {
578 b.Write(buf)
579 b.Read(buf)
580 if i == 0 {
581 cap0 = b.Cap()
582 }
583 }
584 cap1 := b.Cap()
585 // (*Buffer).grow allows for 2x capacity slop before sliding,
586 // so set our error threshold at 3x.
587 if cap1 > cap0*3 {
588 t.Errorf("buffer cap = %d; too big (grew from %d)", cap1, cap0)
589 }
590}
591
592func BenchmarkWriteByte(b *testing.B) {
593 const n = 4 << 10

Callers

nothing calls this directly

Calls 3

WriteMethod · 0.95
ReadMethod · 0.95
CapMethod · 0.95

Tested by

no test coverage detected