1
// Copyright 2013 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
5
// Pool is no-op under race detector, so all these tests do not work.
16
// Note: the tests in this file are (largely) taken directly from
17
// $GOROOT/src/sync/pool_test.go, with the
18
// exception of all the GC-driven behaviour
19
// which has been removed.
21
func TestPool(t *testing.T) {
24
t.Fatal("expected empty")
28
// Note: we don't care what order the values come out
29
// in - the sync implementation works like a queue
30
// where the portable implementation works like a stack.
31
g := make([]string, 2)
32
g[0] = p.Get().(string)
33
g[1] = p.Get().(string)
35
if want := []string{"a", "b"}; !reflect.DeepEqual(g, want) {
36
t.Fatalf("got %q want %q", g, want)
38
if g := p.Get(); g != nil {
39
t.Fatalf("got %#v; want nil", g)
45
func TestPoolNew(t *testing.T) {
48
New: func() interface{} {
53
if v := p.Get(); v != 1 {
54
t.Fatalf("got %v; want 1", v)
56
if v := p.Get(); v != 2 {
57
t.Fatalf("got %v; want 2", v)
60
if v := p.Get(); v != 42 {
61
t.Fatalf("got %v; want 42", v)
63
if v := p.Get(); v != 3 {
64
t.Fatalf("got %v; want 3", v)
68
func TestPoolStress(t *testing.T) {
75
done := make(chan bool)
76
for i := 0; i < P; i++ {
79
for j := 0; j < N; j++ {
85
if v != nil && v.(int) != 0 {
86
t.Fatalf("expect 0, got %v", v)
92
for i := 0; i < P; i++ {