Make Results private

This commit is contained in:
Tomás Senart
2013-09-10 18:58:49 +01:00
parent 4b2e010bee
commit eeb8c96adc
2 changed files with 18 additions and 17 deletions

2
.gitignore vendored
View File

@@ -24,5 +24,5 @@ _testmain.go
vegeta
vegeta.test
targets.txt
vegeta-*.tar.gz
lib/lib.test

View File

@@ -8,6 +8,17 @@ import (
"time"
)
// Result represents the metrics defined out of an http.Response
// generated by each target hit
type Result struct {
Code uint16
Timestamp time.Time
Timing time.Duration
BytesOut uint64
BytesIn uint64
Error error
}
// Attack hits the passed Targets (http.Requests) at the rate specified for
// duration time and then waits for all the requests to come back.
// The results of the attack are put into a slice which is returned.
@@ -15,7 +26,7 @@ func Attack(targets Targets, rate uint64, duration time.Duration) []Result {
total := rate * uint64(duration.Seconds())
hits := make(chan *http.Request, total)
res := make(chan Result, total)
results := make(Results, total)
results := make(results, total)
// Scatter
go drill(rate, hits, res)
for i := 0; i < cap(hits); i++ {
@@ -33,22 +44,12 @@ func Attack(targets Targets, rate uint64, duration time.Duration) []Result {
return results
}
// Result represents the metrics we want out of an http.Response
type Result struct {
Code uint16
Timestamp time.Time
Timing time.Duration
BytesOut uint64
BytesIn uint64
Error error
}
// results is a slice of Result defined only to be sortable with sort.Interface
type results []Result
// Results is a slice of Result defined only to be sortable with sort.Interface
type Results []Result
func (r Results) Len() int { return len(r) }
func (r Results) Less(i, j int) bool { return r[i].Timestamp.Before(r[j].Timestamp) }
func (r Results) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
func (r results) Len() int { return len(r) }
func (r results) Less(i, j int) bool { return r[i].Timestamp.Before(r[j].Timestamp) }
func (r results) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
// drill loops over the passed reqs channel and executes each request.
// It is throttled to the rate specified.