Files
old-vegeta/main_test.go

32 lines
674 B
Go
Raw Normal View History

package main
import (
"bytes"
"net/http"
"net/http/httptest"
"os"
"sync/atomic"
"testing"
"time"
)
func TestAttackRate(t *testing.T) {
hitCount := uint64(0)
server := httptest.NewServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
atomic.AddUint64(&hitCount, 1)
}),
)
targets, err := NewTargets(bytes.NewBufferString("GET " + server.URL + "\n"))
if err != nil {
t.Fatal(err)
}
2013-08-17 13:47:51 +02:00
rate := uint64(5000)
rep := NewTextReporter()
attack(targets, "random", rate, 1*time.Second, rep)
2013-08-17 13:47:51 +02:00
if hits := atomic.LoadUint64(&hitCount); hits != rate {
rep.Report(os.Stdout)
t.Fatalf("Wrong number of hits: want %d, got %d\n", rate, hits)
}
}