Files
old-vegeta/lib/attack_test.go

25 lines
546 B
Go
Raw Normal View History

package vegeta
import (
"net/http"
"net/http/httptest"
"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)
}),
)
request, _ := http.NewRequest("GET", server.URL, nil)
2013-08-17 13:47:51 +02:00
rate := uint64(5000)
Attack(Targets{request}, rate, 1*time.Second)
2013-08-17 13:47:51 +02:00
if hits := atomic.LoadUint64(&hitCount); hits != rate {
t.Fatalf("Wrong number of hits: want %d, got %d\n", rate, hits)
}
}