(t *testing.T)
| 156 | } |
| 157 | |
| 158 | func 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 | } |
nothing calls this directly
no test coverage detected