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

Function TestResponsesPropagateUpstream

modules/frontend/v1/request_batch_test.go:158–196  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156}
157
158func TestResponsesPropagateUpstream(t *testing.T) {
159 rb := &requestBatch{}
160
161 const totalRequests = 3
162 wg := &sync.WaitGroup{}
163
164 for i := int32(0); i < totalRequests; i++ {
165 responseChan := make(chan *http.Response)
166
167 wg.Add(1)
168 go func(expectedCode int32) {
169 resp := <-responseChan
170 assert.Equal(t, expectedCode, int32(resp.StatusCode))
171 wg.Done()
172 }(i)
173
174 req := httptest.NewRequest("GET", "http://example.com", nil)
175 _ = rb.add(&request{
176 request: pipeline.NewHTTPRequest(req),
177 response: responseChan,
178 })
179 }
180
181 // if the reported results mismatches the actual length we should error
182 err := rb.reportResultsToPipeline(make([]*httpgrpc.HTTPResponse, totalRequests+1))
183 require.Error(t, err)
184
185 responses := make([]*httpgrpc.HTTPResponse, totalRequests)
186 for i := int32(0); i < totalRequests; i++ {
187 responses[i] = &httpgrpc.HTTPResponse{
188 Code: i,
189 }
190 }
191 err = rb.reportResultsToPipeline(responses)
192 require.NoError(t, err)
193
194 wg.Wait()
195 // this test won't return unless all responseChan's receive a response
196}

Callers

nothing calls this directly

Calls 8

addMethod · 0.95
NewHTTPRequestFunction · 0.92
AddMethod · 0.65
DoneMethod · 0.65
ErrorMethod · 0.65
WaitMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected