blob: 34ca9973ff33467e816cab9aedcaaa190c3a30fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
package syncs
import "testing"
func TestPool(t *testing.T) {
var pool Pool[string]
s := pool.Get() // should not panic
if s != "" {
t.Fatalf("got %q, want %q", s, "")
}
pool.New = func() string { return "new" }
s = pool.Get()
if s != "new" {
t.Fatalf("got %q, want %q", s, "new")
}
var found bool
for range 1000 {
pool.Put("something")
found = pool.Get() == "something"
if found {
break
}
}
if !found {
t.Fatalf("unable to get any value put in the pool")
}
}
|