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

Function TestAsyncSharders

modules/frontend/pipeline/async_sharding_test.go:15–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestAsyncSharders(t *testing.T) {
16 expectedRequestCount := 10000
17
18 tcs := []struct {
19 name string
20 responseFn func(next AsyncRoundTripper[combiner.PipelineResponse]) *asyncResponse
21 }{
22 {
23 name: "AsyncSharder",
24 responseFn: func(next AsyncRoundTripper[combiner.PipelineResponse]) *asyncResponse {
25 return NewAsyncSharderFunc(context.Background(), 10, expectedRequestCount, func(i int) Request {
26 if i >= expectedRequestCount {
27 return nil
28 }
29 return NewHTTPRequest(&http.Request{})
30 }, next).(*asyncResponse)
31 },
32 },
33 {
34 name: "AsyncSharder - no limit",
35 responseFn: func(next AsyncRoundTripper[combiner.PipelineResponse]) *asyncResponse {
36 return NewAsyncSharderFunc(context.Background(), 0, expectedRequestCount, func(i int) Request {
37 if i >= expectedRequestCount {
38 return nil
39 }
40 return NewHTTPRequest(&http.Request{})
41 }, next).(*asyncResponse)
42 },
43 },
44 {
45 name: "AsyncSharderLimitedGoroutines",
46 responseFn: func(next AsyncRoundTripper[combiner.PipelineResponse]) *asyncResponse {
47 reqChan := make(chan Request)
48 go func() {
49 for i := 0; i < expectedRequestCount; i++ {
50 reqChan <- NewHTTPRequest(&http.Request{})
51 }
52 close(reqChan)
53 }()
54
55 return NewAsyncSharderChan(context.Background(), 10, reqChan, nil, next).(*asyncResponse)
56 },
57 },
58 }
59
60 for _, tc := range tcs {
61 t.Run(tc.name, func(t *testing.T) {
62 next := AsyncRoundTripperFunc[combiner.PipelineResponse](func(_ Request) (Responses[combiner.PipelineResponse], error) {
63 // return a generic 200
64 return NewHTTPToAsyncResponse(&http.Response{
65 Body: io.NopCloser(strings.NewReader("")),
66 StatusCode: 200,
67 }), nil
68 })
69
70 sharderResp := tc.responseFn(next)
71
72 // drain and count the requests

Callers

nothing calls this directly

Calls 10

NewAsyncSharderFuncFunction · 0.85
NewHTTPRequestFunction · 0.85
NewAsyncSharderChanFunction · 0.85
NewHTTPToAsyncResponseFunction · 0.85
AddMethod · 0.65
DoneMethod · 0.65
NextMethod · 0.65
WaitMethod · 0.65
RunMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected