doParams is optional and is used for Do that passes keys
( c *C, pool *LoadBalancedPool, params sendHttpRequestsParams)
| 62 | |
| 63 | // doParams is optional and is used for Do that passes keys |
| 64 | func sendHttpRequestsWithParams( |
| 65 | c *C, pool *LoadBalancedPool, params sendHttpRequestsParams) map[string]int { |
| 66 | responses := make(chan string, params.numRequests) |
| 67 | |
| 68 | for i := 0; i < params.numRequests; i++ { |
| 69 | i := i |
| 70 | go func() { |
| 71 | req, err := http.NewRequest("GET", "/", nil) |
| 72 | c.Assert(err, IsNil) |
| 73 | var resp *http.Response |
| 74 | // we should test both Do and DoWithParams. That's why we're doing these this way |
| 75 | if params.doParams != nil { |
| 76 | resp, err = pool.DoWithParams(req, params.doParams[i]) |
| 77 | } else { |
| 78 | resp, err = pool.Do(req) |
| 79 | } |
| 80 | c.Assert(err, IsNil) |
| 81 | c.Assert(resp.StatusCode, Equals, 200) |
| 82 | |
| 83 | bodyBytes, err := ioutil.ReadAll(resp.Body) |
| 84 | resp.Body.Close() |
| 85 | c.Assert(err, IsNil) |
| 86 | responses <- string(bodyBytes) |
| 87 | }() |
| 88 | } |
| 89 | |
| 90 | // wait for responses and ensure all servers were accessed |
| 91 | receivedPorts := make(map[string]int) |
| 92 | for i := 0; i < params.numRequests; i++ { |
| 93 | select { |
| 94 | case portStr := <-responses: |
| 95 | count := receivedPorts[portStr] |
| 96 | receivedPorts[portStr] = count + 1 |
| 97 | |
| 98 | case <-time.After(5 * time.Second): |
| 99 | c.FailNow() |
| 100 | } |
| 101 | } |
| 102 | return receivedPorts |
| 103 | } |
no test coverage detected