fix:(transport/http): fix unexpected overriding behavior when return an error (#1984)

* fix:(transport/http): fix unexpected overriding behavior when return an error

* fix:(transport/http): fix broken tests

Co-authored-by: pwli0755 <lipw0755@gmial.com>
status-code-override
pwli 3 years ago committed by chenzhihui
parent 784d96058e
commit ec69624f8a
  1. 12
      transport/http/resolver.go
  2. 2
      transport/http/resolver_test.go

@ -79,17 +79,17 @@ func newResolver(ctx context.Context, discovery registry.Discovery, target *Targ
select { select {
case err := <-done: case err := <-done:
if err != nil { if err != nil {
err := watcher.Stop() stopErr := watcher.Stop()
if err != nil { if stopErr != nil {
r.logger.Errorf("failed to http client watch stop: %v", target) r.logger.Errorf("failed to http client watch stop: %v, error: %+v", target, stopErr)
} }
return nil, err return nil, err
} }
case <-ctx.Done(): case <-ctx.Done():
r.logger.Errorf("http client watch service %v reaching context deadline!", target) r.logger.Errorf("http client watch service %v reaching context deadline!", target)
err := watcher.Stop() stopErr := watcher.Stop()
if err != nil { if stopErr != nil {
r.logger.Errorf("failed to http client watch stop: %v", target) r.logger.Errorf("failed to http client watch stop: %v, error: %+v", target, stopErr)
} }
return nil, ctx.Err() return nil, ctx.Err()
} }

@ -77,10 +77,10 @@ type mockWatch struct {
} }
func (m *mockWatch) Next() ([]*registry.ServiceInstance, error) { func (m *mockWatch) Next() ([]*registry.ServiceInstance, error) {
m.count++
if m.count == 1 { if m.count == 1 {
return nil, errors.New("mock test error") return nil, errors.New("mock test error")
} }
m.count++
instance := &registry.ServiceInstance{ instance := &registry.ServiceInstance{
ID: "1", ID: "1",
Name: "kratos", Name: "kratos",

Loading…
Cancel
Save