mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1601 from jonboulle/client
client: return ErrNoEndpoint when none available
This commit is contained in:
commit
c628d7f412
@ -30,6 +30,7 @@ import (
|
||||
var (
|
||||
ErrTimeout = context.DeadlineExceeded
|
||||
ErrCanceled = context.Canceled
|
||||
ErrNoEndpoints = errors.New("no endpoints available")
|
||||
ErrTooManyRedirects = errors.New("too many redirects")
|
||||
|
||||
DefaultRequestTimeout = 5 * time.Second
|
||||
@ -91,6 +92,9 @@ type httpClusterClient struct {
|
||||
}
|
||||
|
||||
func (c *httpClusterClient) Do(ctx context.Context, act HTTPAction) (resp *http.Response, body []byte, err error) {
|
||||
if len(c.endpoints) == 0 {
|
||||
return nil, nil, ErrNoEndpoints
|
||||
}
|
||||
for _, hc := range c.endpoints {
|
||||
resp, body, err = hc.Do(ctx, act)
|
||||
if err != nil {
|
||||
@ -118,6 +122,9 @@ func (c *httpClusterClient) Sync(ctx context.Context) error {
|
||||
for _, m := range ms {
|
||||
eps = append(eps, m.ClientURLs...)
|
||||
}
|
||||
if len(eps) == 0 {
|
||||
return ErrNoEndpoints
|
||||
}
|
||||
nc, err := newHTTPClusterClient(c.transport, eps)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -234,6 +234,14 @@ func TestHTTPClusterClientDo(t *testing.T) {
|
||||
wantErr: ErrCanceled,
|
||||
},
|
||||
|
||||
// return err if there are no endpoints
|
||||
{
|
||||
client: &httpClusterClient{
|
||||
endpoints: []HTTPClient{},
|
||||
},
|
||||
wantErr: ErrNoEndpoints,
|
||||
},
|
||||
|
||||
// return err if all endpoints return arbitrary errors
|
||||
{
|
||||
client: &httpClusterClient{
|
||||
|
Loading…
x
Reference in New Issue
Block a user