Make Results private
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -24,5 +24,5 @@ _testmain.go
|
|||||||
vegeta
|
vegeta
|
||||||
vegeta.test
|
vegeta.test
|
||||||
targets.txt
|
targets.txt
|
||||||
|
|
||||||
vegeta-*.tar.gz
|
vegeta-*.tar.gz
|
||||||
|
lib/lib.test
|
||||||
|
|||||||
@@ -8,6 +8,17 @@ import (
|
|||||||
"time"
|
"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
|
// Attack hits the passed Targets (http.Requests) at the rate specified for
|
||||||
// duration time and then waits for all the requests to come back.
|
// 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.
|
// 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())
|
total := rate * uint64(duration.Seconds())
|
||||||
hits := make(chan *http.Request, total)
|
hits := make(chan *http.Request, total)
|
||||||
res := make(chan Result, total)
|
res := make(chan Result, total)
|
||||||
results := make(Results, total)
|
results := make(results, total)
|
||||||
// Scatter
|
// Scatter
|
||||||
go drill(rate, hits, res)
|
go drill(rate, hits, res)
|
||||||
for i := 0; i < cap(hits); i++ {
|
for i := 0; i < cap(hits); i++ {
|
||||||
@@ -33,22 +44,12 @@ func Attack(targets Targets, rate uint64, duration time.Duration) []Result {
|
|||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
// Result represents the metrics we want out of an http.Response
|
// results is a slice of Result defined only to be sortable with sort.Interface
|
||||||
type Result struct {
|
type results []Result
|
||||||
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
|
func (r results) Len() int { return len(r) }
|
||||||
type Results []Result
|
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.
|
// drill loops over the passed reqs channel and executes each request.
|
||||||
// It is throttled to the rate specified.
|
// It is throttled to the rate specified.
|
||||||
|
|||||||
Reference in New Issue
Block a user