github.com/zuoyebang/bitalostable@v1.0.1-0.20240229032404-e3b99a834294/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/zuoyebang/bitalostable/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  }