(url string, jsonBytes []byte, loopNum int)
| 200 | } |
| 201 | |
| 202 | func runConstantInFlightIteration(url string, jsonBytes []byte, loopNum int) bool { |
| 203 | start := time.Now() |
| 204 | |
| 205 | wasKilled := false |
| 206 | killed := make(chan bool) |
| 207 | c := make(chan os.Signal, 1) |
| 208 | signal.Notify(c, os.Interrupt, syscall.SIGTERM) |
| 209 | go func() { |
| 210 | <-c |
| 211 | killed <- true |
| 212 | }() |
| 213 | |
| 214 | doneChans := make([]chan struct{}, _numConcurrent) |
| 215 | for i := range doneChans { |
| 216 | doneChans[i] = make(chan struct{}) |
| 217 | } |
| 218 | |
| 219 | for i := range doneChans { |
| 220 | doneChan := doneChans[i] |
| 221 | |
| 222 | go func() { |
| 223 | makeRequestLoop(url, jsonBytes) |
| 224 | doneChan <- struct{}{} |
| 225 | }() |
| 226 | } |
| 227 | |
| 228 | LOOP: |
| 229 | for _, doneChan := range doneChans { |
| 230 | select { |
| 231 | case <-killed: |
| 232 | wasKilled = true |
| 233 | break LOOP |
| 234 | case <-doneChan: |
| 235 | continue |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | elapsed := time.Now().Sub(start) |
| 240 | requestRate := float64(_requestCount.Load()) / elapsed.Seconds() |
| 241 | fmt.Printf("\nelapsed time: %s | %d requests @ %f req/s | %d succeeded | %d http errors | %d go errors\n", elapsed, _requestCount.Load(), requestRate, _successCount.Load(), _httpErrCount.Load(), _goErrCount.Load()) |
| 242 | |
| 243 | return wasKilled |
| 244 | } |
| 245 | |
| 246 | func makeRequestLoop(url string, jsonBytes []byte) { |
| 247 | var i int |
no test coverage detected