(b *testing.B)
| 177 | } |
| 178 | |
| 179 | func BenchmarkChainUnaryInterceptor(b *testing.B) { |
| 180 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 181 | defer cancel() |
| 182 | for _, n := range []int{1, 3, 5, 10} { |
| 183 | n := n |
| 184 | b.Run(strconv.Itoa(n), func(b *testing.B) { |
| 185 | interceptors := make([]UnaryServerInterceptor, 0, n) |
| 186 | for i := 0; i < n; i++ { |
| 187 | interceptors = append(interceptors, func( |
| 188 | ctx context.Context, req any, _ *UnaryServerInfo, handler UnaryHandler, |
| 189 | ) (any, error) { |
| 190 | return handler(ctx, req) |
| 191 | }) |
| 192 | } |
| 193 | |
| 194 | s := NewServer(ChainUnaryInterceptor(interceptors...)) |
| 195 | b.ReportAllocs() |
| 196 | b.ResetTimer() |
| 197 | for i := 0; i < b.N; i++ { |
| 198 | if _, err := s.opts.unaryInt(ctx, nil, nil, |
| 199 | func(context.Context, any) (any, error) { |
| 200 | return nil, nil |
| 201 | }, |
| 202 | ); err != nil { |
| 203 | b.Fatal(err) |
| 204 | } |
| 205 | } |
| 206 | }) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | func BenchmarkChainStreamInterceptor(b *testing.B) { |
| 211 | for _, n := range []int{1, 3, 5, 10} { |
nothing calls this directly
no test coverage detected