forked from grafana/k6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
variable_looping_vus.go
94 lines (81 loc) · 2.91 KB
/
variable_looping_vus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
*
* k6 - a next-generation load testing tool
* Copyright (C) 2019 Load Impact
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package scheduler
import (
"fmt"
"time"
"github.com/loadimpact/k6/lib/types"
null "gopkg.in/guregu/null.v3"
)
const variableLoopingVUsType = "variable-looping-vus"
func init() {
RegisterConfigType(variableLoopingVUsType, func(name string, rawJSON []byte) (Config, error) {
config := NewVariableLoopingVUsConfig(name)
err := strictJSONUnmarshal(rawJSON, &config)
return config, err
})
}
// Stage contains
type Stage struct {
Duration types.NullDuration `json:"duration"`
Target null.Int `json:"target"` // TODO: maybe rename this to endVUs? something else?
}
// VariableLoopingVUsConfig stores the configuration for the stages scheduler
type VariableLoopingVUsConfig struct {
BaseConfig
StartVUs null.Int `json:"startVUs"`
Stages []Stage `json:"stages"`
}
// NewVariableLoopingVUsConfig returns a VariableLoopingVUsConfig with its default values
func NewVariableLoopingVUsConfig(name string) VariableLoopingVUsConfig {
return VariableLoopingVUsConfig{BaseConfig: NewBaseConfig(name, variableLoopingVUsType, false)}
}
// Make sure we implement the Config interface
var _ Config = &VariableLoopingVUsConfig{}
// Validate makes sure all options are configured and valid
func (vlvc VariableLoopingVUsConfig) Validate() []error {
errors := vlvc.BaseConfig.Validate()
if vlvc.StartVUs.Int64 < 0 {
errors = append(errors, fmt.Errorf("the number of start VUs shouldn't be negative"))
}
return append(errors, validateStages(vlvc.Stages)...)
}
// GetMaxVUs returns the absolute maximum number of possible concurrently running VUs
func (vlvc VariableLoopingVUsConfig) GetMaxVUs() int64 {
maxVUs := vlvc.StartVUs.Int64
for _, s := range vlvc.Stages {
if s.Target.Int64 > maxVUs {
maxVUs = s.Target.Int64
}
}
return maxVUs
}
// GetMaxDuration returns the maximum duration time for this scheduler, including
// the specified iterationTimeout, if the iterations are uninterruptible
func (vlvc VariableLoopingVUsConfig) GetMaxDuration() time.Duration {
var maxDuration types.Duration
for _, s := range vlvc.Stages {
maxDuration += s.Duration.Duration
}
if !vlvc.Interruptible.Bool {
maxDuration += vlvc.IterationTimeout.Duration
}
return time.Duration(maxDuration)
}