github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/internal/intern/intern_test.go (about)

     1  // Copyright 2020 The LevelDB-Go and Pebble Authors. All rights reserved. Use
     2  // of this source code is governed by a BSD-style license that can be found in
     3  // the LICENSE file.
     4  
     5  package intern
     6  
     7  import (
     8  	"bytes"
     9  	"testing"
    10  
    11  	"github.com/cockroachdb/pebble/internal/invariants"
    12  )
    13  
    14  func TestBytes(t *testing.T) {
    15  	if invariants.RaceEnabled {
    16  		// sync.Pool is a no-op under -race, making this test fail.
    17  		t.Skip("not supported under -race")
    18  	}
    19  
    20  	const abc = "abc"
    21  	s := bytes.Repeat([]byte(abc), 100)
    22  	n := testing.AllocsPerRun(100, func() {
    23  		for i := 0; i < 100; i++ {
    24  			_ = Bytes(s[i*len(abc) : (i+1)*len(abc)])
    25  		}
    26  	})
    27  	if n > 0 {
    28  		t.Fatalf("Bytes allocated %d, want 0", int(n))
    29  	}
    30  }