MCPcopy Index your code
hub / github.com/ContentSquare/chproxy / executeTwoConcurrentRequests

Function executeTwoConcurrentRequests

main_test.go:1196–1249  ·  view source on GitHub ↗

executeTwoConcurrentRequests concurrently executes 2 requests for the same query. Results are asserted according to the specified input parameters.

(t *testing.T, query string, firstStatusCode, secondStatusCode int,
	firstBody, secondBody string)

Source from the content-addressed store, hash-verified

1194// executeTwoConcurrentRequests concurrently executes 2 requests for the same query.
1195// Results are asserted according to the specified input parameters.
1196func executeTwoConcurrentRequests(t *testing.T, query string, firstStatusCode, secondStatusCode int,
1197 firstBody, secondBody string) {
1198 u := fmt.Sprintf("http://127.0.0.1:9090?query=%s&user=concurrent_user", url.QueryEscape(query))
1199
1200 var wg sync.WaitGroup
1201 wg.Add(2)
1202 var resp1 string
1203 var resp2 string
1204 errs := make(chan error, 0)
1205 defer close(errs)
1206 errors := make([]error, 0)
1207 go func() {
1208 for err := range errs {
1209 errors = append(errors, err)
1210 }
1211 }()
1212 go func() {
1213 defer wg.Done()
1214 req, err := http.NewRequest("GET", u, nil)
1215 checkErr(t, err)
1216 resp, err := httpRequest(t, req, firstStatusCode)
1217 if err != nil {
1218 errs <- err
1219 return
1220 }
1221 resp1 = bbToString(t, resp.Body)
1222 }()
1223
1224 go func() {
1225 defer wg.Done()
1226 time.Sleep(20 * time.Millisecond)
1227 req, err := http.NewRequest("GET", u, nil)
1228 checkErr(t, err)
1229 resp, err := httpRequest(t, req, secondStatusCode)
1230 if err != nil {
1231 errs <- err
1232 return
1233 }
1234 resp2 = bbToString(t, resp.Body)
1235 }()
1236 wg.Wait()
1237
1238 if len(errors) != 0 {
1239 t.Fatalf("concurrent test scenario failed due to: %v", errors)
1240 }
1241
1242 if !strings.Contains(resp1, firstBody) {
1243 t.Fatalf("concurrent test scenario: unexpected resp body: %s, expected : %s", resp1, firstBody)
1244 }
1245
1246 if !strings.Contains(resp2, secondBody) {
1247 t.Fatalf("concurrent test scenario: unexpected resp body: %s, expected : %s", resp2, secondBody)
1248 }
1249}
1250
1251var bytesWithInvalidUTFPairs = []byte{239, 191, 189, 1, 32, 50, 239, 191}
1252

Callers 1

TestServeFunction · 0.85

Calls 4

checkErrFunction · 0.85
httpRequestFunction · 0.85
bbToStringFunction · 0.85
ContainsMethod · 0.80

Tested by

no test coverage detected