mirror of
https://github.com/aykhans/dodo.git
synced 2025-07-02 00:16:20 +00:00
✨ Add duration
This commit is contained in:
@ -16,8 +16,8 @@ const cliUsageText = `Usage:
|
||||
|
||||
Examples:
|
||||
|
||||
Simple usage only with URL:
|
||||
dodo -u https://example.com
|
||||
Simple usage:
|
||||
dodo -u https://example.com -o 1m
|
||||
|
||||
Usage with config file:
|
||||
dodo -f /path/to/config/file/config.json
|
||||
@ -25,7 +25,7 @@ Usage with config file:
|
||||
Usage with all flags:
|
||||
dodo -f /path/to/config/file/config.json \
|
||||
-u https://example.com -m POST \
|
||||
-d 10 -r 1000 -t 3s \
|
||||
-d 10 -r 1000 -o 3m -t 3s \
|
||||
-b "body1" -body "body2" \
|
||||
-H "header1:value1" -header "header2:value2" \
|
||||
-p "param1=value1" -param "param2=value2" \
|
||||
@ -39,8 +39,9 @@ Flags:
|
||||
-y, -yes bool Answer yes to all questions (default %v)
|
||||
-f, -config-file string Path to the local config file or http(s) URL of the config file
|
||||
-d, -dodos uint Number of dodos(threads) (default %d)
|
||||
-r, -requests uint Number of total requests (default %d)
|
||||
-t, -timeout Duration Timeout for each request (e.g. 400ms, 15s, 1m10s) (default %v)
|
||||
-r, -requests uint Number of total requests
|
||||
-o, -duration Time Maximum duration for the test (e.g. 30s, 1m, 5h)
|
||||
-t, -timeout Time Timeout for each request (e.g. 400ms, 15s, 1m10s) (default %v)
|
||||
-u, -url string URL for stress testing
|
||||
-m, -method string HTTP Method for the request (default %s)
|
||||
-b, -body [string] Body for the request (e.g. "body text")
|
||||
@ -55,7 +56,6 @@ func (config *Config) ReadCLI() (types.ConfigFile, error) {
|
||||
cliUsageText+"\n",
|
||||
DefaultYes,
|
||||
DefaultDodosCount,
|
||||
DefaultRequestCount,
|
||||
DefaultTimeout,
|
||||
DefaultMethod,
|
||||
)
|
||||
@ -70,6 +70,7 @@ func (config *Config) ReadCLI() (types.ConfigFile, error) {
|
||||
dodosCount = uint(0)
|
||||
requestCount = uint(0)
|
||||
timeout time.Duration
|
||||
duration time.Duration
|
||||
)
|
||||
|
||||
{
|
||||
@ -94,6 +95,9 @@ func (config *Config) ReadCLI() (types.ConfigFile, error) {
|
||||
flag.UintVar(&requestCount, "requests", 0, "Number of total requests")
|
||||
flag.UintVar(&requestCount, "r", 0, "Number of total requests")
|
||||
|
||||
flag.DurationVar(&duration, "duration", 0, "Maximum duration of the test")
|
||||
flag.DurationVar(&duration, "o", 0, "Maximum duration of the test")
|
||||
|
||||
flag.DurationVar(&timeout, "timeout", 0, "Timeout for each request (e.g. 400ms, 15s, 1m10s)")
|
||||
flag.DurationVar(&timeout, "t", 0, "Timeout for each request (e.g. 400ms, 15s, 1m10s)")
|
||||
|
||||
@ -139,6 +143,8 @@ func (config *Config) ReadCLI() (types.ConfigFile, error) {
|
||||
config.DodosCount = utils.ToPtr(dodosCount)
|
||||
case "requests", "r":
|
||||
config.RequestCount = utils.ToPtr(requestCount)
|
||||
case "duration", "o":
|
||||
config.Duration = &types.Duration{Duration: duration}
|
||||
case "timeout", "t":
|
||||
config.Timeout = &types.Timeout{Duration: timeout}
|
||||
case "yes", "y":
|
||||
|
@ -20,7 +20,8 @@ const (
|
||||
DefaultMethod string = "GET"
|
||||
DefaultTimeout time.Duration = time.Second * 10
|
||||
DefaultDodosCount uint = 1
|
||||
DefaultRequestCount uint = 1
|
||||
DefaultRequestCount uint = 0
|
||||
DefaultDuration time.Duration = 0
|
||||
DefaultYes bool = false
|
||||
)
|
||||
|
||||
@ -32,6 +33,7 @@ type RequestConfig struct {
|
||||
Timeout time.Duration
|
||||
DodosCount uint
|
||||
RequestCount uint
|
||||
Duration time.Duration
|
||||
Yes bool
|
||||
Params types.Params
|
||||
Headers types.Headers
|
||||
@ -47,6 +49,7 @@ func NewRequestConfig(conf *Config) *RequestConfig {
|
||||
Timeout: conf.Timeout.Duration,
|
||||
DodosCount: *conf.DodosCount,
|
||||
RequestCount: *conf.RequestCount,
|
||||
Duration: conf.Duration.Duration,
|
||||
Yes: *conf.Yes,
|
||||
Params: conf.Params,
|
||||
Headers: conf.Headers,
|
||||
@ -57,6 +60,9 @@ func NewRequestConfig(conf *Config) *RequestConfig {
|
||||
}
|
||||
|
||||
func (rc *RequestConfig) GetValidDodosCountForRequests() uint {
|
||||
if rc.RequestCount == 0 {
|
||||
return rc.DodosCount
|
||||
}
|
||||
return min(rc.DodosCount, rc.RequestCount)
|
||||
}
|
||||
|
||||
@ -95,7 +101,17 @@ func (rc *RequestConfig) Print() {
|
||||
t.AppendSeparator()
|
||||
t.AppendRow(table.Row{"Dodos", rc.DodosCount})
|
||||
t.AppendSeparator()
|
||||
t.AppendRow(table.Row{"Requests", rc.RequestCount})
|
||||
if rc.RequestCount > 0 {
|
||||
t.AppendRow(table.Row{"Requests", rc.RequestCount})
|
||||
} else {
|
||||
t.AppendRow(table.Row{"Requests"})
|
||||
}
|
||||
t.AppendSeparator()
|
||||
if rc.Duration > 0 {
|
||||
t.AppendRow(table.Row{"Duration", rc.Duration})
|
||||
} else {
|
||||
t.AppendRow(table.Row{"Duration"})
|
||||
}
|
||||
t.AppendSeparator()
|
||||
t.AppendRow(table.Row{"Params", rc.Params.String()})
|
||||
t.AppendSeparator()
|
||||
@ -116,6 +132,7 @@ type Config struct {
|
||||
Timeout *types.Timeout `json:"timeout" yaml:"timeout"`
|
||||
DodosCount *uint `json:"dodos" yaml:"dodos"`
|
||||
RequestCount *uint `json:"requests" yaml:"requests"`
|
||||
Duration *types.Duration `json:"duration" yaml:"duration"`
|
||||
Yes *bool `json:"yes" yaml:"yes"`
|
||||
Params types.Params `json:"params" yaml:"params"`
|
||||
Headers types.Headers `json:"headers" yaml:"headers"`
|
||||
@ -162,8 +179,8 @@ func (c *Config) Validate() []error {
|
||||
if utils.IsNilOrZero(c.DodosCount) {
|
||||
errs = append(errs, errors.New("dodos count must be greater than 0"))
|
||||
}
|
||||
if utils.IsNilOrZero(c.RequestCount) {
|
||||
errs = append(errs, errors.New("request count must be greater than 0"))
|
||||
if utils.IsNilOrZero(c.Duration) && utils.IsNilOrZero(c.RequestCount) {
|
||||
errs = append(errs, errors.New("you should provide at least one of duration or request count"))
|
||||
}
|
||||
|
||||
for i, proxy := range c.Proxies {
|
||||
@ -197,6 +214,9 @@ func (config *Config) MergeConfig(newConfig *Config) {
|
||||
if newConfig.RequestCount != nil {
|
||||
config.RequestCount = newConfig.RequestCount
|
||||
}
|
||||
if newConfig.Duration != nil {
|
||||
config.Duration = newConfig.Duration
|
||||
}
|
||||
if newConfig.Yes != nil {
|
||||
config.Yes = newConfig.Yes
|
||||
}
|
||||
@ -230,6 +250,9 @@ func (config *Config) SetDefaults() {
|
||||
if config.RequestCount == nil {
|
||||
config.RequestCount = utils.ToPtr(DefaultRequestCount)
|
||||
}
|
||||
if config.Duration == nil {
|
||||
config.Duration = &types.Duration{Duration: DefaultDuration}
|
||||
}
|
||||
if config.Yes == nil {
|
||||
config.Yes = utils.ToPtr(DefaultYes)
|
||||
}
|
||||
|
Reference in New Issue
Block a user