(t *testing.T)
| 114 | } |
| 115 | |
| 116 | func TestAttackSignalTwice(t *testing.T) { |
| 117 | t.Parallel() |
| 118 | |
| 119 | const ( |
| 120 | attackDuration = 10 * time.Second // The attack should never take this long. |
| 121 | ) |
| 122 | |
| 123 | server := httptest.NewServer( |
| 124 | http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}), |
| 125 | ) |
| 126 | defer server.Close() |
| 127 | |
| 128 | tr := vegeta.NewStaticTargeter(vegeta.Target{Method: "GET", URL: server.URL}) |
| 129 | atk := vegeta.NewAttacker() |
| 130 | rate := vegeta.Rate{Freq: 1, Per: time.Second} |
| 131 | |
| 132 | var buf bytes.Buffer |
| 133 | writer := bufio.NewWriter(&buf) |
| 134 | enc := vegeta.NewEncoder(writer) |
| 135 | sig := make(chan os.Signal, 1) |
| 136 | res := atk.Attack(tr, rate, attackDuration, "") |
| 137 | |
| 138 | var wg sync.WaitGroup |
| 139 | wg.Add(1) |
| 140 | go func() { |
| 141 | defer wg.Done() |
| 142 | processAttack(atk, res, enc, sig, nil) |
| 143 | }() |
| 144 | |
| 145 | // Exit as soon as possible. |
| 146 | sig <- os.Interrupt |
| 147 | sig <- os.Interrupt |
| 148 | wg.Wait() |
| 149 | writer.Flush() |
| 150 | |
| 151 | metrics, err := decodeMetrics(buf) |
| 152 | if err != nil { |
| 153 | t.Error(err) |
| 154 | } |
| 155 | if got, max := metrics.Duration, time.Second; got > max { |
| 156 | t.Errorf("attack duration too long. got %+v, max: %+v", got, max) |
| 157 | } |
| 158 | } |
nothing calls this directly
no test coverage detected