MCPcopy Index your code
hub / github.com/klauspost/compress / TestNewDecoderMemoryHighMem

Function TestNewDecoderMemoryHighMem

zstd/decoder_test.go:284–347  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

282}
283
284func TestNewDecoderMemoryHighMem(t *testing.T) {
285 defer timeout(60 * time.Second)()
286 var testdata bytes.Buffer
287 enc, err := NewWriter(&testdata, WithWindowSize(32<<10), WithSingleSegment(false))
288 if err != nil {
289 t.Fatal(err)
290 }
291 // Write 256KB
292 for i := range 256 {
293 tmp := strings.Repeat(string([]byte{byte(i)}), 1024)
294 _, err := enc.Write([]byte(tmp))
295 if err != nil {
296 t.Fatal(err)
297 }
298 }
299 err = enc.Close()
300 if err != nil {
301 t.Fatal(err)
302 }
303
304 var n = 50
305 if testing.Short() {
306 n = 10
307 }
308
309 // 16K buffer
310 var tmp [16 << 10]byte
311
312 var before, after runtime.MemStats
313 runtime.GC()
314 runtime.ReadMemStats(&before)
315
316 var decs = make([]*Decoder, n)
317 for i := range decs {
318 // Wrap in NopCloser to avoid shortcut.
319 input := io.NopCloser(bytes.NewBuffer(testdata.Bytes()))
320 decs[i], err = NewReader(input, WithDecoderConcurrency(1), WithDecoderLowmem(false))
321 if err != nil {
322 t.Fatal(err)
323 }
324 }
325
326 for i := range decs {
327 _, err := io.ReadFull(decs[i], tmp[:])
328 if err != nil {
329 t.Fatal(err)
330 }
331 }
332
333 runtime.GC()
334 runtime.ReadMemStats(&after)
335 size := (after.HeapInuse - before.HeapInuse) / uint64(n) / 1024
336
337 const expect = 3915
338 t.Log(size, "KiB per decoder")
339 // This is not exact science, but fail if we suddenly get more than 2x what we expect.
340 if size > expect*2 && !testing.Short() {
341 t.Errorf("expected < %dKB per decoder, got %d", expect, size)

Callers

nothing calls this directly

Calls 12

WriteMethod · 0.95
CloseMethod · 0.95
timeoutFunction · 0.85
WithWindowSizeFunction · 0.85
WithSingleSegmentFunction · 0.85
WithDecoderConcurrencyFunction · 0.85
WithDecoderLowmemFunction · 0.85
FatalMethod · 0.80
NewWriterFunction · 0.70
NewReaderFunction · 0.70
BytesMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…