| 95 | } |
| 96 | |
| 97 | func (g *generator) Stop() Result { |
| 98 | // Trigger the generator to stop. |
| 99 | close(g.stop) |
| 100 | |
| 101 | // Wait for the generator to exit. |
| 102 | t := time.NewTimer(g.StopTimeout) |
| 103 | select { |
| 104 | case <-g.stopped: |
| 105 | t.Stop() |
| 106 | if g.result.TotalRequests == 0 { |
| 107 | g.t.Fatal("no requests completed before stopping the traffic generator") |
| 108 | } |
| 109 | return g.result |
| 110 | case <-t.C: |
| 111 | g.t.Fatal("timed out waiting for result") |
| 112 | } |
| 113 | // Can never happen, but the compiler doesn't know that Fatal terminates |
| 114 | return Result{} |
| 115 | } |
| 116 | |
| 117 | func fillInDefaults(cfg *Config) { |
| 118 | if cfg.Interval == 0 { |