func TestStream(t *testing.T) { a := "≠≠≠≠≠" b := "•••••" d := time.Millisecond r := &fixedResolver{[]string{a}, d} p := pool.Stream(r, "irrelevant", pool.RoundRobin) if err := waitGet(p, time.Millisecond); err != nil { t.Fatal(err) } have, err := p.Get() if err != nil { t.Fatalf("Get (1): %s", err) } if want := a; want != have { t.Errorf("want %q, have %q", want, have) } r.hosts = []string{b} time.Sleep(3 * (d / 2)) have, err = p.Get() if err != nil { t.Fatalf("Get (2): %s", err) } if want := b; want != have { t.Errorf("want %q, have %q", want, have) } }
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) } }
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 }