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

Function TestAsyncResponseFansIn

modules/frontend/pipeline/responses_test.go:157–194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

155}
156
157func TestAsyncResponseFansIn(t *testing.T) {
158 leakOpts := goleak.IgnoreCurrent()
159
160 // create a random hierarchy of async responses and add a bunch of responses.
161 // count the added responses and confirm the number we pull is the same.
162 wg := sync.WaitGroup{}
163 rootResp := newAsyncResponse()
164
165 expected := 0
166 wg.Add(1)
167 go func() {
168 defer wg.Done()
169 defer rootResp.SendComplete()
170
171 expected = addResponses(rootResp)
172 }()
173
174 actual := 0
175 wg.Add(1)
176 go func() {
177 defer wg.Done()
178
179 for {
180 resp, done, err := rootResp.Next(context.Background())
181 if done {
182 return
183 }
184 actual++
185 require.NoError(t, err)
186 require.NotNil(t, resp)
187 }
188 }()
189
190 wg.Wait()
191 require.Equal(t, expected, actual)
192
193 goleak.VerifyNone(t, leakOpts)
194}
195
196func addResponses(r *asyncResponse) int {
197 responsesToAdd := rand.Intn(5)

Callers

nothing calls this directly

Calls 8

newAsyncResponseFunction · 0.85
addResponsesFunction · 0.85
SendCompleteMethod · 0.80
AddMethod · 0.65
DoneMethod · 0.65
NextMethod · 0.65
WaitMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected