Documentation ¶
Index ¶
- Constants
- Variables
- func NewHTTPClientContext(ctx context.Context, client *HTTPClient) context.Context
- func NewLoadTestContext(ctx context.Context, lt *LoadTest) context.Context
- func NewStorageContext(ctx context.Context, s *Storage) context.Context
- func NewUserContext(ctx context.Context, u User) context.Context
- func RunAPIServer(lt *LoadTest) error
- type Config
- type DefaultUser
- func (du *DefaultUser) Context() context.Context
- func (du *DefaultUser) ID() int64
- func (du *DefaultUser) SetContext(ctx context.Context)
- func (du *DefaultUser) SetID(id int64)
- func (du *DefaultUser) SetStatus(us UserStatusType)
- func (du *DefaultUser) Sleep()
- func (du *DefaultUser) SleepSeconds(seconds int)
- func (du *DefaultUser) Spawn()
- func (du *DefaultUser) Status() UserStatusType
- func (du *DefaultUser) Tick()
- type HTTPClient
- func (c *HTTPClient) Delete(path string) (*HTTPResponse, error)
- func (c *HTTPClient) Get(path string) (*HTTPResponse, error)
- func (c *HTTPClient) Head(path string) (*HTTPResponse, error)
- func (c *HTTPClient) Options(path string) (*HTTPResponse, error)
- func (c *HTTPClient) Patch(path string, body []byte) (*HTTPResponse, error)
- func (c *HTTPClient) Post(path string, body []byte) (*HTTPResponse, error)
- func (c *HTTPClient) PostForm(path string, data url.Values) (*HTTPResponse, error)
- func (c *HTTPClient) Put(path string, body []byte) (*HTTPResponse, error)
- func (c *HTTPClient) Request(method string, path string, body []byte) (*HTTPResponse, error)
- type HTTPResponse
- type LoadTest
- type Statistics
- type StatusType
- type Storage
- type Task
- type TaskFunc
- type TaskOptions
- type TaskRun
- type TaskSelectionStrategyType
- type TaskStats
- type User
- type UserStatusType
Constants ¶
View Source
const RPSTimeWindow = 10
Variables ¶
View Source
var ErrInvalidStorageValue = errors.New("invalid storage value")
Functions ¶
func NewHTTPClientContext ¶
func NewHTTPClientContext(ctx context.Context, client *HTTPClient) context.Context
func NewLoadTestContext ¶
func RunAPIServer ¶
Types ¶
type Config ¶
type Config struct { // Host to bind the REST API to. default all (empty string). APIHost string `json:"api_host"` // Port to bind the REST API to, default 4141 APIPort int `json:"api_port"` NumUsers int `json:"num_users"` // How many users to spawn each second NumSpawnPerSecond int `json:"num_spawn_per_second"` // Default 10 seconds RequestTimeout int `json:"request_timeout"` // Custom user type to override the DefaultUser UserType User `json:"-"` // Min sleep time between tasks in seconds MinSleepTime int `json:"min_sleep_time"` // Max sleep time between tasks in seconds MaxSleepTime int `json:"max_sleep_time"` // Verbose logging Verbose bool `json:"verbose"` // If we should start spawning users on startup SpawnOnStartup bool `json:"spawn_on_startup"` // Logging params LogOutput io.Writer `json:"-"` LogPrefix string `json:"log_prefix"` LogFlags int `json:"log_flags"` }
func NewConfigFromFlags ¶
func NewConfigFromFlags() Config
type DefaultUser ¶
type DefaultUser struct {
// contains filtered or unexported fields
}
func NewDefaultUser ¶
func NewDefaultUser(task *Task) *DefaultUser
func (*DefaultUser) Context ¶
func (du *DefaultUser) Context() context.Context
func (*DefaultUser) ID ¶
func (du *DefaultUser) ID() int64
func (*DefaultUser) SetContext ¶
func (du *DefaultUser) SetContext(ctx context.Context)
func (*DefaultUser) SetID ¶
func (du *DefaultUser) SetID(id int64)
func (*DefaultUser) SetStatus ¶
func (du *DefaultUser) SetStatus(us UserStatusType)
func (*DefaultUser) Sleep ¶
func (du *DefaultUser) Sleep()
func (*DefaultUser) SleepSeconds ¶
func (du *DefaultUser) SleepSeconds(seconds int)
func (*DefaultUser) Spawn ¶
func (du *DefaultUser) Spawn()
func (*DefaultUser) Status ¶
func (du *DefaultUser) Status() UserStatusType
func (*DefaultUser) Tick ¶
func (du *DefaultUser) Tick()
type HTTPClient ¶
type HTTPClient struct { // These headers will be set in all requests Headers http.Header // If true, 4xx-5xx status code will return an error, defaults to true ErrorOnErrorCode bool // contains filtered or unexported fields }
func HTTPClientFromContext ¶
func HTTPClientFromContext(ctx context.Context) *HTTPClient
func NewHTTPClient ¶
func NewHTTPClient(ctx context.Context, baseURI string) *HTTPClient
func (*HTTPClient) Delete ¶
func (c *HTTPClient) Delete(path string) (*HTTPResponse, error)
func (*HTTPClient) Get ¶
func (c *HTTPClient) Get(path string) (*HTTPResponse, error)
func (*HTTPClient) Head ¶
func (c *HTTPClient) Head(path string) (*HTTPResponse, error)
func (*HTTPClient) Options ¶
func (c *HTTPClient) Options(path string) (*HTTPResponse, error)
func (*HTTPClient) Patch ¶
func (c *HTTPClient) Patch(path string, body []byte) (*HTTPResponse, error)
func (*HTTPClient) Post ¶
func (c *HTTPClient) Post(path string, body []byte) (*HTTPResponse, error)
func (*HTTPClient) PostForm ¶
func (c *HTTPClient) PostForm(path string, data url.Values) (*HTTPResponse, error)
func (*HTTPClient) Put ¶
func (c *HTTPClient) Put(path string, body []byte) (*HTTPResponse, error)
func (*HTTPClient) Request ¶
func (c *HTTPClient) Request(method string, path string, body []byte) (*HTTPResponse, error)
type HTTPResponse ¶
func (*HTTPResponse) JSON ¶
func (resp *HTTPResponse) JSON(out interface{}) error
type LoadTest ¶
type LoadTest struct { Config Config `json:"config"` Status StatusType `json:"status"` // Map of created users UserMap map[int64]User `json:"-"` UserMapLock sync.Mutex `json:"-"` TaskRunChan chan *TaskRun `json:"-"` Stats *Statistics `json:"stats"` Log *log.Logger `json:"-"` // Target number of user to spawn TargetUserNum int `json:"target_user_num"` }
func FromContext ¶
func NewLoadTest ¶
type Statistics ¶
type Statistics struct { sync.Mutex StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` NumTotal int64 `json:"num_total"` RunningUsers int `json:"num_users"` NumSuccessful int64 `json:"num_successful"` NumFailed int64 `json:"num_failed"` TotalDuration int64 `json:"total_duration"` // unix-timestamp -> count map to calculate a current RPS value RPSMap map[int64]int64 `json:"-"` Tasks map[string]*TaskStats `json:"tasks"` CurrentRPS float32 `json:"current_rps"` AverageDuration float32 `json:"average_duration"` }
func NewStatistics ¶
func NewStatistics() *Statistics
func (*Statistics) Calculate ¶
func (ts *Statistics) Calculate()
func (*Statistics) CleanRPSMap ¶
func (ts *Statistics) CleanRPSMap()
func (*Statistics) Reset ¶
func (ts *Statistics) Reset()
type StatusType ¶
type StatusType int
const ( StatusStopped StatusType = iota StatusSpawning StatusRunning StatusStopping )
func (StatusType) MarshalJSON ¶
func (s StatusType) MarshalJSON() ([]byte, error)
func (StatusType) String ¶
func (s StatusType) String() string
func (*StatusType) UnmarshalJSON ¶
func (s *StatusType) UnmarshalJSON(bytes []byte) error
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Local storage for each user instance
func NewStorage ¶
func NewStorage() *Storage
func StorageFromContext ¶
type Task ¶
type Task struct { Name string Parent *Task SubTasks []*Task RunFunc TaskFunc Options TaskOptions }
func NewEntryTask ¶
func NewEntryTask(name string, f TaskFunc, opts TaskOptions) *Task
The entry task is the first task each User run, and only once
func (*Task) AddSection ¶
func (t *Task) AddSection(name string, setup func(*Task), opts TaskOptions) *Task
Adds and returns an empty section Task and passes it to the callback The TaskOptions will be set on the new section task.
func (*Task) AddSubTask ¶
func (t *Task) AddSubTask(name string, f TaskFunc, opts TaskOptions) *Task
type TaskOptions ¶
type TaskOptions struct { SelectionStrategy TaskSelectionStrategyType StepOutWeight int Weight int }
type TaskSelectionStrategyType ¶
type TaskSelectionStrategyType int
const ( TaskSelectionStrategyRandom TaskSelectionStrategyType = iota TaskSelectionStrategyInOrder )
type TaskStats ¶
type TaskStats struct { sync.Mutex Name string `json:"name"` TotalRuns int64 `json:"total_runs"` NumSuccessful int64 `json:"num_successful"` NumFailed int64 `json:"num_failed"` TotalDuration int64 `json:"total_duration"` Metrics map[int64]int64 `json:"-"` Percentiles map[int]int64 `json:"percentiles"` AverageDuration float32 `json:"average_duration"` Errors map[string]int64 `json:"errors"` }
func NewTaskStat ¶
type User ¶
type User interface { ID() int64 SetID(int64) SetStatus(UserStatusType) Status() UserStatusType SetContext(ctx context.Context) Context() context.Context Spawn() Tick() Sleep() SleepSeconds(seconds int) }
func UserFromContext ¶
type UserStatusType ¶
type UserStatusType int
const ( UserStatusStopped UserStatusType = iota UserStatusStopping UserStatusSpawning UserStatusRunning )
func (UserStatusType) String ¶
func (ust UserStatusType) String() string
Source Files ¶
Click to show internal directories.
Click to hide internal directories.