Exemple #1
0
func waitGet(p pool.Pool, max time.Duration) error {
	deadline := time.Now().Add(max)
	for {
		if time.Now().After(deadline) {
			return fmt.Errorf("timeout")
		}
		if _, err := p.Get(); err != nil {
			time.Sleep(max / 10)
			continue
		}
		return nil
	}
}
func TestGets(t *testing.T) {
	var p pool.Pool
	p = pool.RoundRobin([]string{"≠"})
	p = pool.Instrument(p)
	p = pool.Report(ioutil.Discard, p)

	n := 123
	for i := 0; i < n; i++ {
		p.Get()
	}

	want := strconv.FormatInt(int64(n), 10)
	have := expvar.Get(pool.ExpvarKeyGets).String()
	if want != have {
		t.Errorf("want %q, have %q", want, have)
	}
}