How to use verifyRampingVUs method of cmd Package

Best K6 code snippet using cmd.verifyRampingVUs

config_consolidation_test.go

Source:config_consolidation_test.go Github

copy

Full Screen

...79 assert.Equal(t, types.NullDurationFrom(duration), ecc.Duration)80 assert.Equal(t, vus, ecc.MaxVUs) // MaxVUs defaults to VUs unless specified81 }82}83func verifyRampingVUs(startVus null.Int, stages []executor.Stage) func(t *testing.T, c Config) {84 return func(t *testing.T, c Config) {85 exec := c.Scenarios[lib.DefaultScenarioName]86 require.NotEmpty(t, exec)87 require.IsType(t, executor.RampingVUsConfig{}, exec)88 clvc, ok := exec.(executor.RampingVUsConfig)89 require.True(t, ok)90 assert.Equal(t, startVus, clvc.StartVUs)91 assert.Equal(t, startVus, c.VUs)92 assert.Equal(t, stages, clvc.Stages)93 assert.Len(t, c.Stages, len(stages))94 for i, s := range stages {95 assert.Equal(t, s.Duration, c.Stages[i].Duration)96 assert.Equal(t, s.Target, c.Stages[i].Target)97 }98 }99}100// A helper function that accepts (duration in second, VUs) pairs and returns101// a valid slice of stage structs102func buildStages(durationsAndVUs ...int64) []executor.Stage {103 l := len(durationsAndVUs)104 if l%2 != 0 {105 panic("wrong len")106 }107 result := make([]executor.Stage, 0, l/2)108 for i := 0; i < l; i += 2 {109 result = append(result, executor.Stage{110 Duration: types.NullDurationFrom(time.Duration(durationsAndVUs[i]) * time.Second),111 Target: null.IntFrom(durationsAndVUs[i+1]),112 })113 }114 return result115}116type file struct {117 filepath, contents string118}119func getFS(files []file) afero.Fs {120 fs := afero.NewMemMapFs()121 for _, f := range files {122 must(afero.WriteFile(fs, f.filepath, []byte(f.contents), 0o644)) // modes don't matter in the afero.MemMapFs123 }124 return fs125}126type opts struct {127 cli []string128 env []string129 runner *lib.Options130 fs afero.Fs131 cmds []string132}133// exp contains the different events or errors we expect our test case to trigger.134// for space and clarity, we use the fact that by default, all of the struct values are false135type exp struct {136 cliParseError bool137 cliReadError bool138 consolidationError bool // Note: consolidationError includes validation errors from envconfig.Process()139 derivationError bool140 validationErrors bool141 logWarning bool142}143// A hell of a complicated test case, that still doesn't test things fully...144type configConsolidationTestCase struct {145 options opts146 expected exp147 customValidator func(t *testing.T, c Config)148}149func getConfigConsolidationTestCases() []configConsolidationTestCase {150 defaultConfig := func(jsonConfig string) afero.Fs {151 return getFS([]file{{152 filepath.Join(".config", "loadimpact", "k6", defaultConfigFileName), // TODO: improve153 jsonConfig,154 }})155 }156 I := null.IntFrom // shortcut for "Valid" (i.e. user-specified) ints157 // This is a function, because some of these test cases actually need for the init() functions158 // to be executed, since they depend on defaultConfigFilePath159 return []configConsolidationTestCase{160 // Check that no options will result in 1 VU 1 iter value for execution161 {opts{}, exp{}, verifyOneIterPerOneVU},162 // Verify some CLI errors163 {opts{cli: []string{"--blah", "blah"}}, exp{cliParseError: true}, nil},164 {opts{cli: []string{"--duration", "blah"}}, exp{cliParseError: true}, nil},165 {opts{cli: []string{"--duration", "1000"}}, exp{cliParseError: true}, nil}, // intentionally unsupported166 {opts{cli: []string{"--iterations", "blah"}}, exp{cliParseError: true}, nil},167 {opts{cli: []string{"--execution", ""}}, exp{cliParseError: true}, nil},168 {opts{cli: []string{"--stage", "10:20s"}}, exp{cliReadError: true}, nil},169 {opts{cli: []string{"--stage", "1000:20"}}, exp{cliReadError: true}, nil}, // intentionally unsupported170 // Check if CLI shortcuts generate correct execution values171 {opts{cli: []string{"--vus", "1", "--iterations", "5"}}, exp{}, verifySharedIters(I(1), I(5))},172 {opts{cli: []string{"-u", "2", "-i", "6"}}, exp{}, verifySharedIters(I(2), I(6))},173 {opts{cli: []string{"-d", "123s"}}, exp{}, verifyConstLoopingVUs(null.NewInt(1, false), 123*time.Second)},174 {opts{cli: []string{"-u", "3", "-d", "30s"}}, exp{}, verifyConstLoopingVUs(I(3), 30*time.Second)},175 {opts{cli: []string{"-u", "4", "--duration", "60s"}}, exp{}, verifyConstLoopingVUs(I(4), 1*time.Minute)},176 {177 opts{cli: []string{"--stage", "20s:10", "-s", "3m:5"}},178 exp{},179 verifyRampingVUs(null.NewInt(1, false), buildStages(20, 10, 180, 5)),180 },181 {182 opts{cli: []string{"-s", "1m6s:5", "--vus", "10"}},183 exp{},184 verifyRampingVUs(null.NewInt(10, true), buildStages(66, 5)),185 },186 {opts{cli: []string{"-u", "1", "-i", "6", "-d", "10s"}}, exp{}, func(t *testing.T, c Config) {187 verifySharedIters(I(1), I(6))(t, c)188 sharedIterConfig, ok := c.Scenarios[lib.DefaultScenarioName].(executor.SharedIterationsConfig)189 require.True(t, ok)190 assert.Equal(t, sharedIterConfig.MaxDuration.TimeDuration(), 10*time.Second)191 }},192 // This should get a validation error since VUs are more than the shared iterations193 {opts{cli: []string{"--vus", "10", "-i", "6"}}, exp{validationErrors: true}, verifySharedIters(I(10), I(6))},194 {opts{cli: []string{"-s", "10s:5", "-s", "10s:"}}, exp{validationErrors: true}, nil},195 {opts{fs: defaultConfig(`{"stages": [{"duration": "20s"}], "vus": 10}`)}, exp{validationErrors: true}, nil},196 // These should emit a derivation error197 {opts{cli: []string{"-u", "2", "-d", "10s", "-s", "10s:20"}}, exp{derivationError: true}, nil},198 {opts{cli: []string{"-u", "3", "-i", "5", "-s", "10s:20"}}, exp{derivationError: true}, nil},199 {opts{cli: []string{"-u", "3", "-d", "0"}}, exp{derivationError: true}, nil},200 {201 opts{runner: &lib.Options{202 VUs: null.IntFrom(5),203 Duration: types.NullDurationFrom(44 * time.Second),204 Stages: []lib.Stage{205 {Duration: types.NullDurationFrom(3 * time.Second), Target: I(20)},206 },207 }}, exp{derivationError: true}, nil,208 },209 {opts{fs: defaultConfig(`{"scenarios": {}}`)}, exp{logWarning: true}, verifyOneIterPerOneVU},210 // Test if environment variable shortcuts are working as expected211 {opts{env: []string{"K6_VUS=5", "K6_ITERATIONS=15"}}, exp{}, verifySharedIters(I(5), I(15))},212 {opts{env: []string{"K6_VUS=10", "K6_DURATION=20s"}}, exp{}, verifyConstLoopingVUs(I(10), 20*time.Second)},213 {opts{env: []string{"K6_VUS=10", "K6_DURATION=10000"}}, exp{}, verifyConstLoopingVUs(I(10), 10*time.Second)},214 {215 opts{env: []string{"K6_STAGES=2m30s:11,1h1m:100"}},216 exp{},217 verifyRampingVUs(null.NewInt(1, false), buildStages(150, 11, 3660, 100)),218 },219 {220 opts{env: []string{"K6_STAGES=100s:100,0m30s:0", "K6_VUS=0"}},221 exp{},222 verifyRampingVUs(null.NewInt(0, true), buildStages(100, 100, 30, 0)),223 },224 {opts{env: []string{"K6_STAGES=1000:100"}}, exp{consolidationError: true}, nil}, // intentionally unsupported225 // Test if JSON configs work as expected226 {opts{fs: defaultConfig(`{"iterations": 77, "vus": 7}`)}, exp{}, verifySharedIters(I(7), I(77))},227 {opts{fs: defaultConfig(`wrong-json`)}, exp{consolidationError: true}, nil},228 {opts{fs: getFS(nil), cli: []string{"--config", "/my/config.file"}}, exp{consolidationError: true}, nil},229 // Test combinations between options and levels230 {opts{cli: []string{"--vus", "1"}}, exp{}, verifyOneIterPerOneVU},231 {opts{cli: []string{"--vus", "10"}}, exp{logWarning: true}, verifyOneIterPerOneVU},232 {233 opts{234 fs: getFS([]file{{"/my/config.file", `{"vus": 8, "duration": "2m"}`}}),235 cli: []string{"--config", "/my/config.file"},236 }, exp{}, verifyConstLoopingVUs(I(8), 120*time.Second),237 },238 {239 opts{240 fs: getFS([]file{{"/my/config.file", `{"duration": 20000}`}}),241 cli: []string{"--config", "/my/config.file"},242 }, exp{}, verifyConstLoopingVUs(null.NewInt(1, false), 20*time.Second),243 },244 {245 opts{246 fs: defaultConfig(`{"stages": [{"duration": "20s", "target": 20}], "vus": 10}`),247 env: []string{"K6_DURATION=15s"},248 cli: []string{"--stage", ""},249 },250 exp{logWarning: true},251 verifyOneIterPerOneVU,252 },253 {254 opts{255 runner: &lib.Options{VUs: null.IntFrom(5), Duration: types.NullDurationFrom(50 * time.Second)},256 cli: []string{"--stage", "5s:5"},257 },258 exp{},259 verifyRampingVUs(I(5), buildStages(5, 5)),260 },261 {262 opts{263 fs: defaultConfig(`{"stages": [{"duration": "20s", "target": 10}]}`),264 runner: &lib.Options{VUs: null.IntFrom(5)},265 },266 exp{},267 verifyRampingVUs(I(5), buildStages(20, 10)),268 },269 {270 opts{271 fs: defaultConfig(`{"stages": [{"duration": "20s", "target": 10}]}`),272 runner: &lib.Options{VUs: null.IntFrom(5)},273 env: []string{"K6_VUS=15", "K6_ITERATIONS=17"},274 },275 exp{},276 verifySharedIters(I(15), I(17)),277 },278 {279 opts{280 fs: defaultConfig(`{"stages": [{"duration": "11s", "target": 11}]}`),281 runner: &lib.Options{VUs: null.IntFrom(22)},282 env: []string{"K6_VUS=33"},283 cli: []string{"--stage", "44s:44", "-s", "55s:55"},284 },285 exp{},286 verifyRampingVUs(null.NewInt(33, true), buildStages(44, 44, 55, 55)),287 },288 // TODO: test the future full overwriting of the duration/iterations/stages/execution options289 {290 opts{291 fs: defaultConfig(`{292 "scenarios": { "someKey": {293 "executor": "constant-vus", "vus": 10, "duration": "60s", "gracefulStop": "10s",294 "startTime": "70s", "env": {"test": "mest"}, "exec": "someFunc"295 }}}`),296 env: []string{"K6_ITERATIONS=25"},297 cli: []string{"--vus", "12"},298 },299 exp{},300 verifySharedIters(I(12), I(25)),...

Full Screen

Full Screen

verifyRampingVUs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx := context.Background()4 r, err := lib.NewRunner(ctx, lib.Options{5 Throw: lib.Bool(true),6 NoSetup: lib.Bool(true),7 NoTeardown: lib.Bool(true),8 NoUsageReport: lib.Bool(true),9 })10 if err != nil {11 panic(err)12 }13 executorConfig := executor.PerVUIterationsConfig{14 BaseConfig: executor.BaseConfig{15 GracefulStop: types.NullDurationFrom(10 * time.Second),16 StartTime: types.NullDurationFrom(0 * time.Second),17 Duration: types.NullDurationFrom(10 * time.Second),18 MaxVUs: types.NullInt64From(10),19 },20 Iterations: types.NullInt64From(10),21 }22 executor, err := executor.NewPerVUIterations(executorConfig)23 if err != nil {24 panic(err)25 }26 engine, err := lib.NewEngine(ctx, r, executor)27 if err != nil {28 panic(err)29 }30 loader, err := loader.New(loader.SourceData{31 URLs: []loader.Source{32 {33 },34 },35 })36 if err != nil {37 panic(err)38 }39 scheduler, err := lib.NewScheduler(ctx, engine)40 if err != nil {41 panic(err)42 }43 runner, err := lib.NewRunner(ctx, lib.Options{44 Throw: lib.Bool(true),45 NoSetup: lib.Bool(true),46 NoTeardown: lib.Bool(true),47 NoUsageReport: lib.Bool(true),48 })49 if err != nil {50 panic(err)51 }

Full Screen

Full Screen

verifyRampingVUs

Using AI Code Generation

copy

Full Screen

1func (c *cmd) verifyRampingVUs() error {2 if c.vusMax < c.vus {3 return fmt.Errorf("max VUs (%d) must be bigger than or equal to the start VUs (%d)", c.vusMax, c.vus)4 }5 if c.vusMax > c.vus && c.duration.String() == "" {6 return fmt.Errorf("the duration argument is required if max VUs (%d) is bigger than the start VUs (%d)", c.vusMax, c.vus)7 }8}9func (c *cmd) verifyRampingVUs() error {10 if c.vusMax < c.vus {11 return fmt.Errorf("max VUs (%d) must be bigger than or equal to the start VUs (%d)", c.vusMax, c.vus)12 }13 if c.vusMax > c.vus && c.duration.String() == "" {14 return fmt.Errorf("the duration argument is required if max VUs (%d) is bigger than the start VUs (%d)", c.vusMax, c.vus)15 }16}17func (c *cmd) verifyRampingVUs() error {18 if c.vusMax < c.vus {19 return fmt.Errorf("max VUs (%d) must be bigger than or equal to the start VUs (%d)", c.vusMax, c.vus)20 }21 if c.vusMax > c.vus && c.duration.String() == "" {22 return fmt.Errorf("the duration argument is required if max VUs (%d) is bigger than the start VUs (%d)", c.vusMax, c.vus)23 }24}25func (c *cmd) verifyRampingVUs() error {26 if c.vusMax < c.vus {27 return fmt.Errorf("max VUs (%d) must be bigger than or equal to the start VUs (%d)", c.vusMax, c.vus)28 }29 if c.vusMax > c.vus && c.duration.String() == "" {

Full Screen

Full Screen

verifyRampingVUs

Using AI Code Generation

copy

Full Screen

1func main() {2 cmd.verifyRampingVUs()3}4func main() {5 cmd.verifyRampingVUs()6}7func main() {8 cmd.verifyRampingVUs()9}10func main() {11 cmd.verifyRampingVUs()12}13func main() {14 cmd.verifyRampingVUs()15}16func main() {17 cmd.verifyRampingVUs()18}19func main() {20 cmd.verifyRampingVUs()21}22func main() {23 cmd.verifyRampingVUs()24}25func main() {26 cmd.verifyRampingVUs()27}28func main() {29 cmd.verifyRampingVUs()30}31func main() {32 cmd.verifyRampingVUs()33}34func main() {35 cmd.verifyRampingVUs()36}

Full Screen

Full Screen

verifyRampingVUs

Using AI Code Generation

copy

Full Screen

1func (c *cmd) verifyRampingVUs() error {2 if c.rampingVUs {3 if c.duration == 0 {4 return fmt.Errorf("duration must be specified if rampingVUs is true")5 }6 if c.stages != nil {7 return fmt.Errorf("stages must not be specified if rampingVUs is true")8 }9 } else {10 if c.stages == nil {11 return fmt.Errorf("either stages or rampingVUs must be specified")12 }13 }14}15func (c *cmd) verifyRampingVUs() error {16 if c.rampingVUs {17 if c.duration == 0 {18 return fmt.Errorf("duration must be specified if rampingVUs is true")19 }20 if c.stages != nil {21 return fmt.Errorf("stages must not be specified if rampingVUs is true")22 }23 } else {24 if c.stages == nil {25 return fmt.Errorf("either stages or rampingVUs must be specified")26 }27 }28}29func (c *cmd) verifyRampingVUs() error {30 if c.rampingVUs {31 if c.duration == 0 {32 return fmt.Errorf("duration must be specified if rampingVUs is true")33 }34 if c.stages != nil {35 return fmt.Errorf("stages must not be specified if rampingVUs is true")36 }37 } else {38 if c.stages == nil {39 return fmt.Errorf("either stages or rampingVUs must be specified")40 }41 }42}43func (c *cmd) verifyRampingVUs() error {44 if c.rampingVUs {45 if c.duration == 0 {46 return fmt.Errorf("duration must be specified if rampingVUs is true")47 }48 if c.stages != nil {49 return fmt.Errorf("stages must not be specified if rampingVUs is true")50 }51 } else {

Full Screen

Full Screen

verifyRampingVUs

Using AI Code Generation

copy

Full Screen

1func main() {2 ctx, cancel := context.WithCancel(context.Background())3 defer cancel()4 r, err := js.New(&loader.SourceData{5 URL: &url.URL{Path: "/path/to/script.js"},6 Data: []byte(script),7 }, afero.NewOsFs(), lib.RuntimeOptions{})8 if err != nil {9 panic(err)10 }11 e, err := js.NewVUExecutor(r, lib.ExecutorConfig{12 StartTime: time.Now(),13 MaxVUs: null.IntFrom(100),14 })15 if err != nil {16 panic(err)17 }18 c := &cmd{19 logger: logrus.New(),20 }21 if err := c.verifyRampingVUs(ctx); err != nil {22 panic(err)23 }24}25func main() {26 ctx, cancel := context.WithCancel(context.Background())27 defer cancel()28 r, err := js.New(&loader.SourceData{29 URL: &url.URL{Path: "/path/to/script.js"},30 Data: []byte(script),31 }, afero.NewOsFs(), lib.RuntimeOptions{})32 if err != nil {33 panic(err)34 }35 e, err := js.NewVUExecutor(r, lib.ExecutorConfig{36 StartTime: time.Now(),37 MaxVUs: null.IntFrom(100),38 })39 if err != nil {40 panic(err)41 }42 c := &cmd{43 logger: logrus.New(),44 }45 if err := c.verifyRampingVUs(ctx); err != nil {46 panic(err)47 }48}

Full Screen

Full Screen

verifyRampingVUs

Using AI Code Generation

copy

Full Screen

1func (c *cmd) verifyRampingVUs() {2 for _, v := range c.VUs {3 if v.Ramping {4 if v.RampTo < v.RampFrom {5 log.Fatalf("RampTo: %d should be greater than RampFrom: %d", v.RampTo, v.RampFrom)6 }7 if v.RampTo == v.RampFrom {8 log.Fatalf("RampTo: %d should not be equal to RampFrom: %d", v.RampTo, v.RampFrom)9 }10 if v.RampTo < 0 {11 log.Fatalf("RampTo: %d should be greater than 0", v.RampTo)12 }13 if v.RampFrom < 0 {14 log.Fatalf("RampFrom: %d should be greater than 0", v.RampFrom)15 }16 }17 }18}19func (c *cmd) verifyRampingVUs() {20 for _, v := range c.VUs {21 if v.Ramping {22 if v.RampTo < v.RampFrom {23 log.Fatalf("RampTo: %d should be greater than RampFrom: %d", v.RampTo, v.RampFrom)24 }25 if v.RampTo == v.RampFrom {26 log.Fatalf("RampTo: %d should not be equal to RampFrom: %d", v.RampTo, v.RampFrom)27 }28 if v.RampTo < 0 {29 log.Fatalf("RampTo: %d should be greater than 0", v.RampTo)30 }31 if v.RampFrom < 0 {32 log.Fatalf("RampFrom: %d should be greater than 0", v.RampFrom)33 }34 }35 }36}37func (c *cmd) verifyRampingVUs() {38 for _, v := range c.VUs {39 if v.Ramping {40 if v.RampTo < v.RampFrom {41 log.Fatalf("RampTo: %d should be greater than RampFrom: %d", v.RampTo, v

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful