Пример #1
0
func TestReport(t *testing.T) {
	buf := &bytes.Buffer{}
	resolver := &fixedResolver{[]string{"foo"}, time.Millisecond}
	pool := pool.Report(buf, pool.Stream(resolver, "irrelevant", pool.RoundRobin))
	if _, err := pool.Get(); err != nil {
		t.Fatal(err)
	}
	if want, have := `{"host":"foo"}`+"\n", buf.String(); want != have {
		t.Errorf("want %q, have %q", want, have)
	}
}
Пример #2
0
func (r *registry) get(host string) pool.Pool {
	r.Lock()
	defer r.Unlock()
	p, ok := r.m[host]
	if !ok {
		p = pool.Stream(r.resolver, host, r.factory)
		p = pool.Report(r.reportWriter, p)
		p = pool.Instrument(p)
		r.m[host] = p
	}
	return p
}
Пример #3
0
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)
	}
}