MCPcopy
hub / github.com/grafana/tempo / TestRunRequests

Function TestRunRequests

modules/querier/worker/frontend_processor_test.go:26–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24}
25
26func 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
61func TestHandleSendError(t *testing.T) {
62 inf := newFrontendProcessor(Config{}, nil, log.NewNopLogger())

Callers

nothing calls this directly

Calls 9

newFrontendProcessorFunction · 0.85
RequestHandlerFuncFuncType · 0.85
UnregisterMethod · 0.80
runRequestsMethod · 0.80
SleepMethod · 0.65
LenMethod · 0.65
WriteMethod · 0.65
EqualMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected