Example #1
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)
	}
}
func TestRoundRobin(t *testing.T) {
	var (
		hosts = []string{"a", "b", "c"}
		p     = pool.RoundRobin(hosts)
		want  = []string{"a", "b", "c", "a", "b", "c", "a"}
		have  []string
	)

	for i := 0; i < 7; i++ {
		host, err := p.Get()
		if err != nil {
			t.Errorf("Get %d: %s", i, err)
			continue
		}
		have = append(have, host)
	}

	if !reflect.DeepEqual(want, have) {
		t.Errorf("want %v, have %v", want, have)
	}
}