Codebase list golang-github-go-kit-kit / 1eba920
More user-friendly behavior in DNSSRVPublisher If the publisher has been stopped, return an appropriate error message from Endpoints. Thanks, @ChrisHines! Peter Bourgon 8 years ago
3 changed file(s) with 40 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
7878
7979 // Endpoints implements the Publisher interface.
8080 func (p *Publisher) Endpoints() ([]endpoint.Endpoint, error) {
81 return <-p.endpoints, nil
81 select {
82 case endpoints := <-p.endpoints:
83 return endpoints, nil
84 case <-p.quit:
85 return nil, loadbalancer.ErrPublisherStopped
86 }
8287 }
8388
8489 var (
99 "golang.org/x/net/context"
1010
1111 "github.com/go-kit/kit/endpoint"
12 "github.com/go-kit/kit/loadbalancer"
1213 "github.com/go-kit/kit/log"
1314 )
1415
134135 t.Skip("TODO")
135136 }
136137
138 func TestErrPublisherStopped(t *testing.T) {
139 var (
140 name = "my-name"
141 ttl = time.Second
142 factory = func(string) (endpoint.Endpoint, error) { return nil, errors.New("kaboom") }
143 logger = log.NewNopLogger()
144 )
145
146 oldLookup := lookupSRV
147 defer func() { lookupSRV = oldLookup }()
148 lookupSRV = mockLookupSRV([]*net.SRV{}, nil, nil)
149
150 p, err := NewPublisher(name, ttl, factory, logger)
151 if err != nil {
152 t.Fatal(err)
153 }
154
155 p.Stop()
156 _, have := p.Endpoints()
157 if want := loadbalancer.ErrPublisherStopped; want != have {
158 t.Fatalf("want %v, have %v", want, have)
159 }
160 }
161
137162 func mockLookupSRV(addrs []*net.SRV, err error, count *uint64) func(service, proto, name string) (string, []*net.SRV, error) {
138163 return func(service, proto, name string) (string, []*net.SRV, error) {
139164 if count != nil {
00 package loadbalancer
11
2 import "github.com/go-kit/kit/endpoint"
2 import (
3 "errors"
4
5 "github.com/go-kit/kit/endpoint"
6 )
37
48 // Publisher describes something that provides a set of identical endpoints.
59 // Different publisher implementations exist for different kinds of service
711 type Publisher interface {
812 Endpoints() ([]endpoint.Endpoint, error)
913 }
14
15 // ErrPublisherStopped is returned by publishers when the underlying
16 // implementation has been terminated and can no longer serve requests.
17 var ErrPublisherStopped = errors.New("publisher stopped")