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

Function TestAsyncResponsesDoesNotLeak

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

Source from the content-addressed store, hash-verified

213}
214
215func TestAsyncResponsesDoesNotLeak(t *testing.T) {
216 tcs := []struct {
217 name string
218 finalRT func(requestCancel context.CancelFunc) RoundTripperFunc
219 cleanup func()
220 }{
221 {
222 name: "happy path",
223 finalRT: func(_ context.CancelFunc) RoundTripperFunc {
224 return RoundTripperFunc(func(_ Request) (*http.Response, error) {
225 return &http.Response{
226 Body: io.NopCloser(strings.NewReader("foo")),
227 }, nil
228 })
229 },
230 },
231 {
232 name: "error path",
233 finalRT: func(_ context.CancelFunc) RoundTripperFunc {
234 return RoundTripperFunc(func(_ Request) (*http.Response, error) {
235 return nil, errors.New("foo")
236 })
237 },
238 },
239 {
240 name: "combiner bails early",
241 finalRT: func(_ context.CancelFunc) RoundTripperFunc {
242 responseCounter := atomic.Int32{}
243
244 return RoundTripperFunc(func(_ Request) (*http.Response, error) {
245 counter := responseCounter.Add(1)
246 if counter == 2 {
247 return &http.Response{
248 StatusCode: http.StatusNotFound, // force the combiner to bail on the second response
249 Body: io.NopCloser(strings.NewReader("foo")),
250 }, nil
251 }
252
253 return &http.Response{
254 Body: io.NopCloser(strings.NewReader("foo")),
255 }, nil
256 })
257 },
258 },
259 {
260 name: "context cancelled before returned responses",
261 finalRT: func(cancel context.CancelFunc) RoundTripperFunc {
262 go func() {
263 time.Sleep(1 * time.Second)
264 cancel()
265 }()
266
267 return RoundTripperFunc(func(_ Request) (*http.Response, error) {
268 time.Sleep(3 * time.Second)
269
270 return &http.Response{
271 Body: io.NopCloser(strings.NewReader("foo")),
272 }, nil

Callers

nothing calls this directly

Calls 10

NewSearchFunction · 0.92
NewTypedSearchFunction · 0.92
NewHTTPCollectorFunction · 0.85
NewGRPCCollectorFunction · 0.85
TestMethod · 0.80
RoundTripperFuncFuncType · 0.70
AddMethod · 0.65
SleepMethod · 0.65
RoundTripMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected