1
2
3
4
5 package scratch
6
7 import "testing"
8
9 func TestAcquire(t *testing.T) {
10 const n = 1 << 25
11
12 for range 2 {
13 b := Acquire(n)
14 if len(b) != n {
15 t.Fatalf("Acquire(%d) returned %d bytes", n, len(b))
16 }
17 for i := 0; i < n; i += 512 {
18 b[i]++
19 }
20 b[n-1]++
21
22 if b2 := Acquire(n); &b2[0] != &b[0] {
23 t.Error("overlapping Acquire calls returned different buffers")
24 }
25 Release(b)
26 b[0]++
27 Release(b)
28
29 if shared.buf != nil || shared.refs != 0 {
30 t.Errorf("buffer not released: len %d, refs %d", len(shared.buf), shared.refs)
31 }
32 }
33 }
34
View as plain text