(t *testing.T)
| 24 | } |
| 25 | |
| 26 | func TestRunRequests(t *testing.T) { |
| 27 | handler := func(ctx context.Context, r *httpgrpc.HTTPRequest) (*httpgrpc.HTTPResponse, error) { |
| 28 | time.Sleep(time.Millisecond) |
| 29 | return &httpgrpc.HTTPResponse{ |
| 30 | Body: r.Body, |
| 31 | }, nil |
| 32 | } |
| 33 | |
| 34 | inf := newFrontendProcessor(Config{GRPCClientConfig: grpcclient.Config{MaxSendMsgSize: 10}}, RequestHandlerFunc(handler), log.NewNopLogger()) |
| 35 | fp := inf.(*frontendProcessor) |
| 36 | // unregister metric in test avoid panic due to registering it twice in tests |
| 37 | defer prometheus.Unregister(fp.metricRequestsTotal) |
| 38 | |
| 39 | totalRequests := byte(10) |
| 40 | reqs := []*httpgrpc.HTTPRequest{} |
| 41 | for i := byte(0); i < totalRequests; i++ { |
| 42 | reqs = append(reqs, &httpgrpc.HTTPRequest{ |
| 43 | Body: []byte{i}, |
| 44 | }) |
| 45 | } |
| 46 | |
| 47 | resps := fp.runRequests(context.Background(), reqs) |
| 48 | require.Len(t, resps, int(totalRequests)) |
| 49 | |
| 50 | for i, resp := range resps { |
| 51 | require.Equal(t, []byte{byte(i)}, resp.Body) |
| 52 | } |
| 53 | |
| 54 | // check that counter metric is working |
| 55 | m := &dto.Metric{} |
| 56 | err := fp.metricRequestsTotal.Write(m) |
| 57 | require.NoError(t, err) |
| 58 | require.Equal(t, float64(totalRequests), m.Counter.GetValue()) |
| 59 | } |
| 60 | |
| 61 | func TestHandleSendError(t *testing.T) { |
| 62 | inf := newFrontendProcessor(Config{}, nil, log.NewNopLogger()) |
nothing calls this directly
no test coverage detected