mirror of
https://github.com/cubixle/l1.git
synced 2026-04-24 19:54:47 +01:00
adds comments and removes unused options
This commit is contained in:
3
http.go
3
http.go
@@ -5,6 +5,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DefaultHTTPTester is an implementation of a simple load testing func.
|
||||||
|
// It follows the F signature and returns a Result.
|
||||||
|
// Any errors that occur will be set at Result.Error.
|
||||||
func DefaultHTTPTester(target string) *Result {
|
func DefaultHTTPTester(target string) *Result {
|
||||||
result := &Result{}
|
result := &Result{}
|
||||||
client := http.Client{
|
client := http.Client{
|
||||||
|
|||||||
18
l1.go
18
l1.go
@@ -19,10 +19,14 @@ type Runner struct {
|
|||||||
results []*Result
|
results []*Result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewRunner creates a new Runner...
|
||||||
|
// There a bunch of defaults that will be set that can be overwritten
|
||||||
|
// with the Options (Opt) found in opts.go.
|
||||||
|
//
|
||||||
|
// The only error that is returned currently is if no target has been set
|
||||||
|
// with the WithTarget option func.
|
||||||
func NewRunner(opts ...Opt) (*Runner, error) {
|
func NewRunner(opts ...Opt) (*Runner, error) {
|
||||||
r := &Runner{
|
r := &Runner{
|
||||||
RunTime: 60 * time.Second,
|
|
||||||
Timeout: 30 * time.Second,
|
|
||||||
MaxParrellConnections: 10,
|
MaxParrellConnections: 10,
|
||||||
MaxConnections: 10,
|
MaxConnections: 10,
|
||||||
RampUp: 0,
|
RampUp: 0,
|
||||||
@@ -39,10 +43,19 @@ func NewRunner(opts ...Opt) (*Runner, error) {
|
|||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetOpt gives the ability to change the configuration of Runner in a
|
||||||
|
// standardised way after NewRunner has been called.
|
||||||
func (r *Runner) SetOpt(o Opt) {
|
func (r *Runner) SetOpt(o Opt) {
|
||||||
o(r)
|
o(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute runs a worker pool and then fires off requests until MaxConnections
|
||||||
|
// has been reached.
|
||||||
|
//
|
||||||
|
// Execute will block until all requests have been completed.
|
||||||
|
//
|
||||||
|
// All results are aggregated and are accessible via the .Results() method
|
||||||
|
// once the requests have completed.
|
||||||
func (r *Runner) Execute() {
|
func (r *Runner) Execute() {
|
||||||
tasks := []*Task{}
|
tasks := []*Task{}
|
||||||
for i := 0; i < r.MaxConnections; i++ {
|
for i := 0; i < r.MaxConnections; i++ {
|
||||||
@@ -70,5 +83,6 @@ func (r *Runner) Results() *results {
|
|||||||
Results: r.results,
|
Results: r.results,
|
||||||
Target: r.Target,
|
Target: r.Target,
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|||||||
29
opts.go
29
opts.go
@@ -1,46 +1,47 @@
|
|||||||
package l1
|
package l1
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
// Opt
|
// Opt
|
||||||
type Opt func(*Runner)
|
type Opt func(*Runner)
|
||||||
|
|
||||||
|
// WithMaxConns will set the maximum amount of connections
|
||||||
|
// you want the runners to make.
|
||||||
|
//
|
||||||
|
// If this is not passed to the NewRunner() the default will be
|
||||||
|
// set to 10.
|
||||||
func WithMaxConns(amount int) Opt {
|
func WithMaxConns(amount int) Opt {
|
||||||
return func(r *Runner) {
|
return func(r *Runner) {
|
||||||
r.MaxConnections = amount
|
r.MaxConnections = amount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithTimeout(timeInSecs int) Opt {
|
// WithMaxParrellConns will set the max parrell connections
|
||||||
return func(r *Runner) {
|
// you want the runners to use.
|
||||||
r.Timeout = time.Duration(timeInSecs) * time.Second
|
//
|
||||||
}
|
// If this is not passed to the NewRunner() the default will be
|
||||||
}
|
// set to 10.
|
||||||
|
|
||||||
func WithRunTime(timeInSecs int) Opt {
|
|
||||||
return func(r *Runner) {
|
|
||||||
r.RunTime = time.Duration(timeInSecs) * time.Second
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithMaxParrellConns(amount int) Opt {
|
func WithMaxParrellConns(amount int) Opt {
|
||||||
return func(r *Runner) {
|
return func(r *Runner) {
|
||||||
r.MaxParrellConnections = amount
|
r.MaxParrellConnections = amount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithTarget sets the target, the target will be passed to the runner
|
||||||
|
// function.
|
||||||
func WithTarget(target string) Opt {
|
func WithTarget(target string) Opt {
|
||||||
return func(r *Runner) {
|
return func(r *Runner) {
|
||||||
r.Target = target
|
r.Target = target
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithRunFunc will set the function used by the requests pool.
|
||||||
func WithRunFunc(f F) Opt {
|
func WithRunFunc(f F) Opt {
|
||||||
return func(r *Runner) {
|
return func(r *Runner) {
|
||||||
r.RunFunc = f
|
r.RunFunc = f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithRampUp will set the amount of time between each ramp up
|
||||||
|
// stage.
|
||||||
func WithRampUp(seconds int) Opt {
|
func WithRampUp(seconds int) Opt {
|
||||||
return func(r *Runner) {
|
return func(r *Runner) {
|
||||||
r.RampUp = seconds
|
r.RampUp = seconds
|
||||||
|
|||||||
Reference in New Issue
Block a user