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.
This commit is contained in:
Tomás Senart
2013-09-09 01:49:57 +01:00
parent bab3d9f89a
commit f689362188
7 changed files with 38 additions and 30 deletions

View File

@@ -3,7 +3,6 @@ package vegeta
import (
"net/http"
"net/http/httptest"
"os"
"sync/atomic"
"testing"
"time"
@@ -18,10 +17,8 @@ func TestAttackRate(t *testing.T) {
)
request, _ := http.NewRequest("GET", server.URL, nil)
rate := uint64(5000)
rep := NewTextReporter()
Attack(Targets{request}, rate, 1*time.Second, rep)
Attack(Targets{request}, rate, 1*time.Second)
if hits := atomic.LoadUint64(&hitCount); hits != rate {
rep.Report(os.Stdout)
t.Fatalf("Wrong number of hits: want %d, got %d\n", rate, hits)
}
}