Files
old-vegeta/lib/attack_test.go
Tomás Senart f689362188 Decouple Reporters from Attack function
This changeset breaks the API of Attack in order to decouple Reporters
and the Attack function. Attack now returns a slice with
non-deterministic order of Results which one can use on the calling code
with or without Reporters, hence making it much more useful on a library
usage setting.
These developments could be of interest to issue #11 which was closed in
the past.
2013-09-09 03:08:44 +01:00

25 lines
546 B
Go

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)
rate := uint64(5000)
Attack(Targets{request}, rate, 1*time.Second)
if hits := atomic.LoadUint64(&hitCount); hits != rate {
t.Fatalf("Wrong number of hits: want %d, got %d\n", rate, hits)
}
}