MCPcopy
hub / github.com/grpc/grpc-go / TestRetryChainedInterceptor

Method TestRetryChainedInterceptor

server_test.go:134–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

132}
133
134func (s) TestRetryChainedInterceptor(t *testing.T) {
135 var records []int
136 i1 := func(ctx context.Context, req any, _ *UnaryServerInfo, handler UnaryHandler) (resp any, err error) {
137 records = append(records, 1)
138 // call handler twice to simulate a retry here.
139 handler(ctx, req)
140 return handler(ctx, req)
141 }
142 i2 := func(ctx context.Context, req any, _ *UnaryServerInfo, handler UnaryHandler) (resp any, err error) {
143 records = append(records, 2)
144 return handler(ctx, req)
145 }
146 i3 := func(ctx context.Context, req any, _ *UnaryServerInfo, handler UnaryHandler) (resp any, err error) {
147 records = append(records, 3)
148 return handler(ctx, req)
149 }
150
151 ii := chainUnaryInterceptors([]UnaryServerInterceptor{i1, i2, i3})
152
153 handler := func(context.Context, any) (any, error) {
154 return nil, nil
155 }
156
157 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
158 defer cancel()
159
160 ii(ctx, nil, nil, handler)
161 if !cmp.Equal(records, []int{1, 2, 3, 2, 3}) {
162 t.Fatalf("retry failed on chained interceptors: %v", records)
163 }
164}
165
166func (s) TestStreamContext(t *testing.T) {
167 expectedStream := &transport.ServerStream{}

Callers

nothing calls this directly

Calls 3

chainUnaryInterceptorsFunction · 0.85
EqualMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected