(t *testing.T)
| 69 | } |
| 70 | |
| 71 | func TestCallRetry(t *testing.T) { |
| 72 | service := "test.service" |
| 73 | endpoint := "Test.Endpoint" |
| 74 | address := "10.1.10.1" |
| 75 | |
| 76 | var called int |
| 77 | |
| 78 | wrap := func(cf CallFunc) CallFunc { |
| 79 | return func(_ context.Context, _ *registry.Node, _ Request, _ interface{}, _ CallOptions) error { |
| 80 | called++ |
| 81 | if called == 1 { |
| 82 | return errors.InternalServerError("test.error", "retry request") |
| 83 | } |
| 84 | // don't do the call |
| 85 | return nil |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | r := newTestRegistry() |
| 90 | c := NewClient( |
| 91 | Registry(r), |
| 92 | WrapCall(wrap), |
| 93 | Retry(RetryAlways), |
| 94 | Retries(1), |
| 95 | ) |
| 96 | |
| 97 | if err := c.Options().Selector.Init(selector.Registry(r)); err != nil { |
| 98 | t.Fatal("failed to initialize selector", err) |
| 99 | } |
| 100 | |
| 101 | req := c.NewRequest(service, endpoint, nil) |
| 102 | |
| 103 | // test calling remote address |
| 104 | if err := c.Call(context.Background(), req, nil, WithAddress(address)); err != nil { |
| 105 | t.Fatal("call with address error", err) |
| 106 | } |
| 107 | |
| 108 | // num calls |
| 109 | if called < c.Options().CallOptions.Retries+1 { |
| 110 | t.Fatal("request not retried") |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | func TestCallWrapper(t *testing.T) { |
| 115 | var called bool |
nothing calls this directly
no test coverage detected
searching dependent graphs…