MCPcopy
hub / github.com/micro/go-micro / TestCallRetry

Function TestCallRetry

client/rpc_client_test.go:71–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func 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
114func TestCallWrapper(t *testing.T) {
115 var called bool

Callers

nothing calls this directly

Calls 14

OptionsMethod · 0.95
NewRequestMethod · 0.95
CallMethod · 0.95
InternalServerErrorFunction · 0.92
RegistryFunction · 0.92
RetriesFunction · 0.85
FatalMethod · 0.80
newTestRegistryFunction · 0.70
RegistryFunction · 0.70
WrapCallFunction · 0.70
RetryFunction · 0.70
WithAddressFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…