How to use NewRampingVUsConfig method of executor Package

Best K6 code snippet using executor.NewRampingVUsConfig

ramping_vus_test.go

Source:ramping_vus_test.go Github

copy

Full Screen

...34 "go.k6.io/k6/lib/types"35)36func TestRampingVUsConfigValidation(t *testing.T) {37 t.Parallel()38 errs := NewRampingVUsConfig("default").Validate()39 require.NotEmpty(t, errs)40 assert.Contains(t, errs[0].Error(), "one stage has to be specified")41 c := NewRampingVUsConfig("stage")42 c.Stages = []Stage{43 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(12 * time.Second)},44 }45 errs = c.Validate()46 require.Empty(t, errs) // by default StartVUs is 147 c.StartVUs = null.IntFrom(0)48 errs = c.Validate()49 require.NotEmpty(t, errs)50 assert.Contains(t, errs[0].Error(), "greater than 0")51}52func TestRampingVUsRun(t *testing.T) {53 t.Parallel()54 config := RampingVUsConfig{55 BaseConfig: BaseConfig{GracefulStop: types.NullDurationFrom(0)},56 GracefulRampDown: types.NullDurationFrom(0),57 StartVUs: null.IntFrom(5),58 Stages: []Stage{59 {60 Duration: types.NullDurationFrom(1 * time.Second),61 Target: null.IntFrom(5),62 },63 {64 Duration: types.NullDurationFrom(0),65 Target: null.IntFrom(3),66 },67 {68 Duration: types.NullDurationFrom(1 * time.Second),69 Target: null.IntFrom(3),70 },71 },72 }73 var iterCount int6474 et, err := lib.NewExecutionTuple(nil, nil)75 require.NoError(t, err)76 es := lib.NewExecutionState(lib.Options{}, et, 10, 50)77 ctx, cancel, executor, _ := setupExecutor(78 t, config, es,79 simpleRunner(func(ctx context.Context) error {80 // Sleeping for a weird duration somewhat offset from the81 // executor ticks to hopefully keep race conditions out of82 // our control from failing the test.83 time.Sleep(300 * time.Millisecond)84 atomic.AddInt64(&iterCount, 1)85 return nil86 }),87 )88 defer cancel()89 sampleTimes := []time.Duration{90 500 * time.Millisecond,91 1000 * time.Millisecond,92 900 * time.Millisecond,93 }94 errCh := make(chan error)95 go func() { errCh <- executor.Run(ctx, nil, nil) }()96 result := make([]int64, len(sampleTimes))97 for i, d := range sampleTimes {98 time.Sleep(d)99 result[i] = es.GetCurrentlyActiveVUsCount()100 }101 require.NoError(t, <-errCh)102 assert.Equal(t, []int64{5, 3, 0}, result)103 assert.Equal(t, int64(29), atomic.LoadInt64(&iterCount))104}105func TestRampingVUsGracefulStopWaits(t *testing.T) {106 t.Parallel()107 config := RampingVUsConfig{108 BaseConfig: BaseConfig{GracefulStop: types.NullDurationFrom(time.Second)},109 StartVUs: null.IntFrom(1),110 Stages: []Stage{111 {112 Duration: types.NullDurationFrom(1 * time.Second),113 Target: null.IntFrom(1),114 },115 },116 }117 var (118 started = make(chan struct{}) // the iteration started119 stopped = make(chan struct{}) // the iteration stopped120 stop = make(chan struct{}) // the itearation should stop121 )122 et, err := lib.NewExecutionTuple(nil, nil)123 require.NoError(t, err)124 es := lib.NewExecutionState(lib.Options{}, et, 10, 50)125 ctx, cancel, executor, _ := setupExecutor(126 t, config, es,127 simpleRunner(func(ctx context.Context) error {128 close(started)129 defer close(stopped)130 select {131 case <-ctx.Done():132 t.Fatal("The iterations should've ended before the context")133 case <-stop:134 }135 return nil136 }),137 )138 defer cancel()139 errCh := make(chan error)140 go func() { errCh <- executor.Run(ctx, nil, nil) }()141 <-started142 // 500 milliseconds more then the duration and 500 less then the gracefulStop143 time.Sleep(time.Millisecond * 1500)144 close(stop)145 <-stopped146 require.NoError(t, <-errCh)147}148func TestRampingVUsGracefulStopStops(t *testing.T) {149 t.Parallel()150 config := RampingVUsConfig{151 BaseConfig: BaseConfig{GracefulStop: types.NullDurationFrom(time.Second)},152 StartVUs: null.IntFrom(1),153 Stages: []Stage{154 {155 Duration: types.NullDurationFrom(1 * time.Second),156 Target: null.IntFrom(1),157 },158 },159 }160 var (161 started = make(chan struct{}) // the iteration started162 stopped = make(chan struct{}) // the iteration stopped163 stop = make(chan struct{}) // the itearation should stop164 )165 et, err := lib.NewExecutionTuple(nil, nil)166 require.NoError(t, err)167 es := lib.NewExecutionState(lib.Options{}, et, 10, 50)168 ctx, cancel, executor, _ := setupExecutor(169 t, config, es,170 simpleRunner(func(ctx context.Context) error {171 close(started)172 defer close(stopped)173 select {174 case <-ctx.Done():175 case <-stop:176 t.Fatal("The iterations shouldn't have ended before the context")177 }178 return nil179 }),180 )181 defer cancel()182 errCh := make(chan error)183 go func() { errCh <- executor.Run(ctx, nil, nil) }()184 <-started185 // 500 milliseconds more then the gracefulStop + duration186 time.Sleep(time.Millisecond * 2500)187 close(stop)188 <-stopped189 require.NoError(t, <-errCh)190}191func TestRampingVUsGracefulRampDown(t *testing.T) {192 t.Parallel()193 config := RampingVUsConfig{194 BaseConfig: BaseConfig{GracefulStop: types.NullDurationFrom(5 * time.Second)},195 StartVUs: null.IntFrom(2),196 GracefulRampDown: types.NullDurationFrom(5 * time.Second),197 Stages: []Stage{198 {199 Duration: types.NullDurationFrom(1 * time.Second),200 Target: null.IntFrom(2),201 },202 {203 Duration: types.NullDurationFrom(1 * time.Second),204 Target: null.IntFrom(0),205 },206 },207 }208 var (209 started = make(chan struct{}) // the iteration started210 stopped = make(chan struct{}) // the iteration stopped211 stop = make(chan struct{}) // the itearation should stop212 )213 et, err := lib.NewExecutionTuple(nil, nil)214 require.NoError(t, err)215 es := lib.NewExecutionState(lib.Options{}, et, 10, 50)216 ctx, cancel, executor, _ := setupExecutor(217 t, config, es,218 simpleRunner(func(ctx context.Context) error {219 if lib.GetState(ctx).VUID == 1 { // the first VU will wait here to do stuff220 close(started)221 defer close(stopped)222 select {223 case <-ctx.Done():224 t.Fatal("The iterations shouldn't have ended before the context")225 case <-stop:226 }227 } else { // all other (1) VUs will just sleep long enough228 time.Sleep(2500 * time.Millisecond)229 }230 return nil231 }),232 )233 defer cancel()234 errCh := make(chan error)235 go func() { errCh <- executor.Run(ctx, nil, nil) }()236 <-started237 // 500 milliseconds more then the gracefulRampDown + duration238 time.Sleep(2500 * time.Millisecond)239 close(stop)240 <-stopped241 select {242 case err := <-errCh:243 require.NoError(t, err)244 case <-time.After(time.Second): // way too much time245 t.Fatal("Execution should've ended already")246 }247}248// Ensure there's no wobble of VUs during graceful ramp-down, without segments.249// See https://github.com/k6io/k6/issues/1296250func TestRampingVUsRampDownNoWobble(t *testing.T) {251 t.Parallel()252 config := RampingVUsConfig{253 BaseConfig: BaseConfig{GracefulStop: types.NullDurationFrom(0)},254 GracefulRampDown: types.NullDurationFrom(1 * time.Second),255 StartVUs: null.IntFrom(0),256 Stages: []Stage{257 {258 Duration: types.NullDurationFrom(3 * time.Second),259 Target: null.IntFrom(10),260 },261 {262 Duration: types.NullDurationFrom(2 * time.Second),263 Target: null.IntFrom(0),264 },265 },266 }267 et, err := lib.NewExecutionTuple(nil, nil)268 require.NoError(t, err)269 es := lib.NewExecutionState(lib.Options{}, et, 10, 50)270 ctx, cancel, executor, _ := setupExecutor(271 t, config, es,272 simpleRunner(func(ctx context.Context) error {273 time.Sleep(500 * time.Millisecond)274 return nil275 }),276 )277 defer cancel()278 sampleTimes := []time.Duration{279 100 * time.Millisecond,280 3000 * time.Millisecond,281 }282 const rampDownSampleTime = 50 * time.Millisecond283 rampDownSamples := int(time.Duration(284 config.Stages[len(config.Stages)-1].Duration.Duration+config.GracefulRampDown.Duration,285 ) / rampDownSampleTime)286 errCh := make(chan error)287 go func() { errCh <- executor.Run(ctx, nil, nil) }()288 result := make([]int64, len(sampleTimes)+rampDownSamples)289 for i, d := range sampleTimes {290 time.Sleep(d)291 result[i] = es.GetCurrentlyActiveVUsCount()292 }293 // Sample ramp-down at a higher rate294 for i := len(sampleTimes); i < rampDownSamples; i++ {295 time.Sleep(rampDownSampleTime)296 result[i] = es.GetCurrentlyActiveVUsCount()297 }298 require.NoError(t, <-errCh)299 // Some baseline checks300 assert.Equal(t, int64(0), result[0])301 assert.Equal(t, int64(10), result[1])302 assert.Equal(t, int64(0), result[len(result)-1])303 vuChanges := []int64{result[2]}304 // Check ramp-down consistency305 for i := 3; i < len(result[2:]); i++ {306 if result[i] != result[i-1] {307 vuChanges = append(vuChanges, result[i])308 }309 }310 assert.Equal(t, []int64{10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, vuChanges)311}312func TestRampingVUsConfigExecutionPlanExample(t *testing.T) {313 t.Parallel()314 et, err := lib.NewExecutionTuple(nil, nil)315 require.NoError(t, err)316 conf := NewRampingVUsConfig("test")317 conf.StartVUs = null.IntFrom(4)318 conf.Stages = []Stage{319 {Target: null.IntFrom(6), Duration: types.NullDurationFrom(2 * time.Second)},320 {Target: null.IntFrom(1), Duration: types.NullDurationFrom(5 * time.Second)},321 {Target: null.IntFrom(5), Duration: types.NullDurationFrom(4 * time.Second)},322 {Target: null.IntFrom(1), Duration: types.NullDurationFrom(4 * time.Second)},323 {Target: null.IntFrom(4), Duration: types.NullDurationFrom(3 * time.Second)},324 {Target: null.IntFrom(4), Duration: types.NullDurationFrom(2 * time.Second)},325 {Target: null.IntFrom(1), Duration: types.NullDurationFrom(0 * time.Second)},326 {Target: null.IntFrom(1), Duration: types.NullDurationFrom(3 * time.Second)},327 }328 expRawStepsNoZeroEnd := []lib.ExecutionStep{329 {TimeOffset: 0 * time.Second, PlannedVUs: 4},330 {TimeOffset: 1 * time.Second, PlannedVUs: 5},331 {TimeOffset: 2 * time.Second, PlannedVUs: 6},332 {TimeOffset: 3 * time.Second, PlannedVUs: 5},333 {TimeOffset: 4 * time.Second, PlannedVUs: 4},334 {TimeOffset: 5 * time.Second, PlannedVUs: 3},335 {TimeOffset: 6 * time.Second, PlannedVUs: 2},336 {TimeOffset: 7 * time.Second, PlannedVUs: 1},337 {TimeOffset: 8 * time.Second, PlannedVUs: 2},338 {TimeOffset: 9 * time.Second, PlannedVUs: 3},339 {TimeOffset: 10 * time.Second, PlannedVUs: 4},340 {TimeOffset: 11 * time.Second, PlannedVUs: 5},341 {TimeOffset: 12 * time.Second, PlannedVUs: 4},342 {TimeOffset: 13 * time.Second, PlannedVUs: 3},343 {TimeOffset: 14 * time.Second, PlannedVUs: 2},344 {TimeOffset: 15 * time.Second, PlannedVUs: 1},345 {TimeOffset: 16 * time.Second, PlannedVUs: 2},346 {TimeOffset: 17 * time.Second, PlannedVUs: 3},347 {TimeOffset: 18 * time.Second, PlannedVUs: 4},348 {TimeOffset: 20 * time.Second, PlannedVUs: 1},349 }350 rawStepsNoZeroEnd := conf.getRawExecutionSteps(et, false)351 assert.Equal(t, expRawStepsNoZeroEnd, rawStepsNoZeroEnd)352 endOffset, isFinal := lib.GetEndOffset(rawStepsNoZeroEnd)353 assert.Equal(t, 20*time.Second, endOffset)354 assert.Equal(t, false, isFinal)355 rawStepsZeroEnd := conf.getRawExecutionSteps(et, true)356 assert.Equal(t,357 append(expRawStepsNoZeroEnd, lib.ExecutionStep{TimeOffset: 23 * time.Second, PlannedVUs: 0}),358 rawStepsZeroEnd,359 )360 endOffset, isFinal = lib.GetEndOffset(rawStepsZeroEnd)361 assert.Equal(t, 23*time.Second, endOffset)362 assert.Equal(t, true, isFinal)363 // GracefulStop and GracefulRampDown equal to the default 30 sec364 assert.Equal(t, []lib.ExecutionStep{365 {TimeOffset: 0 * time.Second, PlannedVUs: 4},366 {TimeOffset: 1 * time.Second, PlannedVUs: 5},367 {TimeOffset: 2 * time.Second, PlannedVUs: 6},368 {TimeOffset: 33 * time.Second, PlannedVUs: 5},369 {TimeOffset: 42 * time.Second, PlannedVUs: 4},370 {TimeOffset: 50 * time.Second, PlannedVUs: 1},371 {TimeOffset: 53 * time.Second, PlannedVUs: 0},372 }, conf.GetExecutionRequirements(et))373 // Try a longer GracefulStop than the GracefulRampDown374 conf.GracefulStop = types.NullDurationFrom(80 * time.Second)375 assert.Equal(t, []lib.ExecutionStep{376 {TimeOffset: 0 * time.Second, PlannedVUs: 4},377 {TimeOffset: 1 * time.Second, PlannedVUs: 5},378 {TimeOffset: 2 * time.Second, PlannedVUs: 6},379 {TimeOffset: 33 * time.Second, PlannedVUs: 5},380 {TimeOffset: 42 * time.Second, PlannedVUs: 4},381 {TimeOffset: 50 * time.Second, PlannedVUs: 1},382 {TimeOffset: 103 * time.Second, PlannedVUs: 0},383 }, conf.GetExecutionRequirements(et))384 // Try a much shorter GracefulStop than the GracefulRampDown385 conf.GracefulStop = types.NullDurationFrom(3 * time.Second)386 assert.Equal(t, []lib.ExecutionStep{387 {TimeOffset: 0 * time.Second, PlannedVUs: 4},388 {TimeOffset: 1 * time.Second, PlannedVUs: 5},389 {TimeOffset: 2 * time.Second, PlannedVUs: 6},390 {TimeOffset: 26 * time.Second, PlannedVUs: 0},391 }, conf.GetExecutionRequirements(et))392 // Try a zero GracefulStop393 conf.GracefulStop = types.NullDurationFrom(0 * time.Second)394 assert.Equal(t, []lib.ExecutionStep{395 {TimeOffset: 0 * time.Second, PlannedVUs: 4},396 {TimeOffset: 1 * time.Second, PlannedVUs: 5},397 {TimeOffset: 2 * time.Second, PlannedVUs: 6},398 {TimeOffset: 23 * time.Second, PlannedVUs: 0},399 }, conf.GetExecutionRequirements(et))400 // Try a zero GracefulStop and GracefulRampDown, i.e. raw steps with 0 end cap401 conf.GracefulRampDown = types.NullDurationFrom(0 * time.Second)402 assert.Equal(t, rawStepsZeroEnd, conf.GetExecutionRequirements(et))403}404func TestRampingVUsConfigExecutionPlanExampleOneThird(t *testing.T) {405 t.Parallel()406 et, err := lib.NewExecutionTuple(newExecutionSegmentFromString("0:1/3"), nil)407 require.NoError(t, err)408 conf := NewRampingVUsConfig("test")409 conf.StartVUs = null.IntFrom(4)410 conf.Stages = []Stage{411 {Target: null.IntFrom(6), Duration: types.NullDurationFrom(2 * time.Second)},412 {Target: null.IntFrom(1), Duration: types.NullDurationFrom(5 * time.Second)},413 {Target: null.IntFrom(5), Duration: types.NullDurationFrom(4 * time.Second)},414 {Target: null.IntFrom(1), Duration: types.NullDurationFrom(4 * time.Second)},415 {Target: null.IntFrom(4), Duration: types.NullDurationFrom(3 * time.Second)},416 {Target: null.IntFrom(4), Duration: types.NullDurationFrom(2 * time.Second)},417 {Target: null.IntFrom(1), Duration: types.NullDurationFrom(0 * time.Second)},418 {Target: null.IntFrom(1), Duration: types.NullDurationFrom(3 * time.Second)},419 }420 expRawStepsNoZeroEnd := []lib.ExecutionStep{421 {TimeOffset: 0 * time.Second, PlannedVUs: 1},422 {TimeOffset: 1 * time.Second, PlannedVUs: 2},423 {TimeOffset: 4 * time.Second, PlannedVUs: 1},424 {TimeOffset: 7 * time.Second, PlannedVUs: 0},425 {TimeOffset: 8 * time.Second, PlannedVUs: 1},426 {TimeOffset: 11 * time.Second, PlannedVUs: 2},427 {TimeOffset: 12 * time.Second, PlannedVUs: 1},428 {TimeOffset: 15 * time.Second, PlannedVUs: 0},429 {TimeOffset: 16 * time.Second, PlannedVUs: 1},430 {TimeOffset: 20 * time.Second, PlannedVUs: 0},431 }432 rawStepsNoZeroEnd := conf.getRawExecutionSteps(et, false)433 assert.Equal(t, expRawStepsNoZeroEnd, rawStepsNoZeroEnd)434 endOffset, isFinal := lib.GetEndOffset(rawStepsNoZeroEnd)435 assert.Equal(t, 20*time.Second, endOffset)436 assert.Equal(t, true, isFinal)437 rawStepsZeroEnd := conf.getRawExecutionSteps(et, true)438 assert.Equal(t, expRawStepsNoZeroEnd, rawStepsZeroEnd)439 endOffset, isFinal = lib.GetEndOffset(rawStepsZeroEnd)440 assert.Equal(t, 20*time.Second, endOffset)441 assert.Equal(t, true, isFinal)442 // GracefulStop and GracefulRampDown equal to the default 30 sec443 assert.Equal(t, []lib.ExecutionStep{444 {TimeOffset: 0 * time.Second, PlannedVUs: 1},445 {TimeOffset: 1 * time.Second, PlannedVUs: 2},446 {TimeOffset: 42 * time.Second, PlannedVUs: 1},447 {TimeOffset: 50 * time.Second, PlannedVUs: 0},448 }, conf.GetExecutionRequirements(et))449 // Try a longer GracefulStop than the GracefulRampDown450 conf.GracefulStop = types.NullDurationFrom(80 * time.Second)451 assert.Equal(t, []lib.ExecutionStep{452 {TimeOffset: 0 * time.Second, PlannedVUs: 1},453 {TimeOffset: 1 * time.Second, PlannedVUs: 2},454 {TimeOffset: 42 * time.Second, PlannedVUs: 1},455 {TimeOffset: 50 * time.Second, PlannedVUs: 0},456 }, conf.GetExecutionRequirements(et))457 // Try a much shorter GracefulStop than the GracefulRampDown458 conf.GracefulStop = types.NullDurationFrom(3 * time.Second)459 assert.Equal(t, []lib.ExecutionStep{460 {TimeOffset: 0 * time.Second, PlannedVUs: 1},461 {TimeOffset: 1 * time.Second, PlannedVUs: 2},462 {TimeOffset: 26 * time.Second, PlannedVUs: 0},463 }, conf.GetExecutionRequirements(et))464 // Try a zero GracefulStop465 conf.GracefulStop = types.NullDurationFrom(0 * time.Second)466 assert.Equal(t, []lib.ExecutionStep{467 {TimeOffset: 0 * time.Second, PlannedVUs: 1},468 {TimeOffset: 1 * time.Second, PlannedVUs: 2},469 {TimeOffset: 23 * time.Second, PlannedVUs: 0},470 }, conf.GetExecutionRequirements(et))471 // Try a zero GracefulStop and GracefulRampDown, i.e. raw steps with 0 end cap472 conf.GracefulRampDown = types.NullDurationFrom(0 * time.Second)473 assert.Equal(t, rawStepsZeroEnd, conf.GetExecutionRequirements(et))474}475func TestRampingVUsExecutionTupleTests(t *testing.T) {476 t.Parallel()477 conf := NewRampingVUsConfig("test")478 conf.StartVUs = null.IntFrom(4)479 conf.Stages = []Stage{480 {Target: null.IntFrom(6), Duration: types.NullDurationFrom(2 * time.Second)},481 {Target: null.IntFrom(1), Duration: types.NullDurationFrom(5 * time.Second)},482 {Target: null.IntFrom(5), Duration: types.NullDurationFrom(4 * time.Second)},483 {Target: null.IntFrom(1), Duration: types.NullDurationFrom(4 * time.Second)},484 {Target: null.IntFrom(4), Duration: types.NullDurationFrom(3 * time.Second)},485 {Target: null.IntFrom(4), Duration: types.NullDurationFrom(2 * time.Second)},486 {Target: null.IntFrom(1), Duration: types.NullDurationFrom(0 * time.Second)},487 {Target: null.IntFrom(1), Duration: types.NullDurationFrom(3 * time.Second)},488 {Target: null.IntFrom(5), Duration: types.NullDurationFrom(0 * time.Second)},489 {Target: null.IntFrom(5), Duration: types.NullDurationFrom(3 * time.Second)},490 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(0 * time.Second)},491 {Target: null.IntFrom(2), Duration: types.NullDurationFrom(2 * time.Second)},492 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(2 * time.Second)},493 {Target: null.IntFrom(4), Duration: types.NullDurationFrom(4 * time.Second)},494 }495 /*496 Graph of the above:497 ^498 8 |499 7 |500 6 | +501 5 |/ \ + +--+502 4 + \ / \ +-+ | | *503 3 | \ / \ / | | | /504 2 | \ / \ / | | | + /505 1 | + + +--+ |/ \ /506 0 +-------------------------+---+------------------------------>507 01234567890123456789012345678901234567890508 */509 testCases := []struct {510 expectedSteps []lib.ExecutionStep511 et *lib.ExecutionTuple512 }{513 {514 et: mustNewExecutionTuple(nil, nil),515 expectedSteps: []lib.ExecutionStep{516 {TimeOffset: 0 * time.Second, PlannedVUs: 4},517 {TimeOffset: 1 * time.Second, PlannedVUs: 5},518 {TimeOffset: 2 * time.Second, PlannedVUs: 6},519 {TimeOffset: 3 * time.Second, PlannedVUs: 5},520 {TimeOffset: 4 * time.Second, PlannedVUs: 4},521 {TimeOffset: 5 * time.Second, PlannedVUs: 3},522 {TimeOffset: 6 * time.Second, PlannedVUs: 2},523 {TimeOffset: 7 * time.Second, PlannedVUs: 1},524 {TimeOffset: 8 * time.Second, PlannedVUs: 2},525 {TimeOffset: 9 * time.Second, PlannedVUs: 3},526 {TimeOffset: 10 * time.Second, PlannedVUs: 4},527 {TimeOffset: 11 * time.Second, PlannedVUs: 5},528 {TimeOffset: 12 * time.Second, PlannedVUs: 4},529 {TimeOffset: 13 * time.Second, PlannedVUs: 3},530 {TimeOffset: 14 * time.Second, PlannedVUs: 2},531 {TimeOffset: 15 * time.Second, PlannedVUs: 1},532 {TimeOffset: 16 * time.Second, PlannedVUs: 2},533 {TimeOffset: 17 * time.Second, PlannedVUs: 3},534 {TimeOffset: 18 * time.Second, PlannedVUs: 4},535 {TimeOffset: 20 * time.Second, PlannedVUs: 1},536 {TimeOffset: 23 * time.Second, PlannedVUs: 5},537 {TimeOffset: 26 * time.Second, PlannedVUs: 0},538 {TimeOffset: 27 * time.Second, PlannedVUs: 1},539 {TimeOffset: 28 * time.Second, PlannedVUs: 2},540 {TimeOffset: 29 * time.Second, PlannedVUs: 1},541 {TimeOffset: 30 * time.Second, PlannedVUs: 0},542 {TimeOffset: 31 * time.Second, PlannedVUs: 1},543 {TimeOffset: 32 * time.Second, PlannedVUs: 2},544 {TimeOffset: 33 * time.Second, PlannedVUs: 3},545 {TimeOffset: 34 * time.Second, PlannedVUs: 4},546 },547 },548 {549 et: mustNewExecutionTuple(newExecutionSegmentFromString("0:1/3"), nil),550 expectedSteps: []lib.ExecutionStep{551 {TimeOffset: 0 * time.Second, PlannedVUs: 1},552 {TimeOffset: 1 * time.Second, PlannedVUs: 2},553 {TimeOffset: 4 * time.Second, PlannedVUs: 1},554 {TimeOffset: 7 * time.Second, PlannedVUs: 0},555 {TimeOffset: 8 * time.Second, PlannedVUs: 1},556 {TimeOffset: 11 * time.Second, PlannedVUs: 2},557 {TimeOffset: 12 * time.Second, PlannedVUs: 1},558 {TimeOffset: 15 * time.Second, PlannedVUs: 0},559 {TimeOffset: 16 * time.Second, PlannedVUs: 1},560 {TimeOffset: 20 * time.Second, PlannedVUs: 0},561 {TimeOffset: 23 * time.Second, PlannedVUs: 2},562 {TimeOffset: 26 * time.Second, PlannedVUs: 0},563 {TimeOffset: 28 * time.Second, PlannedVUs: 1},564 {TimeOffset: 29 * time.Second, PlannedVUs: 0},565 {TimeOffset: 32 * time.Second, PlannedVUs: 1},566 },567 },568 {569 et: mustNewExecutionTuple(newExecutionSegmentFromString("0:1/3"), newExecutionSegmentSequenceFromString("0,1/3,1")),570 expectedSteps: []lib.ExecutionStep{571 {TimeOffset: 0 * time.Second, PlannedVUs: 1},572 {TimeOffset: 1 * time.Second, PlannedVUs: 2},573 {TimeOffset: 4 * time.Second, PlannedVUs: 1},574 {TimeOffset: 7 * time.Second, PlannedVUs: 0},575 {TimeOffset: 8 * time.Second, PlannedVUs: 1},576 {TimeOffset: 11 * time.Second, PlannedVUs: 2},577 {TimeOffset: 12 * time.Second, PlannedVUs: 1},578 {TimeOffset: 15 * time.Second, PlannedVUs: 0},579 {TimeOffset: 16 * time.Second, PlannedVUs: 1},580 {TimeOffset: 20 * time.Second, PlannedVUs: 0},581 {TimeOffset: 23 * time.Second, PlannedVUs: 2},582 {TimeOffset: 26 * time.Second, PlannedVUs: 0},583 {TimeOffset: 28 * time.Second, PlannedVUs: 1},584 {TimeOffset: 29 * time.Second, PlannedVUs: 0},585 {TimeOffset: 32 * time.Second, PlannedVUs: 1},586 },587 },588 {589 et: mustNewExecutionTuple(newExecutionSegmentFromString("1/3:2/3"), nil),590 expectedSteps: []lib.ExecutionStep{591 {TimeOffset: 0 * time.Second, PlannedVUs: 1},592 {TimeOffset: 1 * time.Second, PlannedVUs: 2},593 {TimeOffset: 4 * time.Second, PlannedVUs: 1},594 {TimeOffset: 7 * time.Second, PlannedVUs: 0},595 {TimeOffset: 8 * time.Second, PlannedVUs: 1},596 {TimeOffset: 11 * time.Second, PlannedVUs: 2},597 {TimeOffset: 12 * time.Second, PlannedVUs: 1},598 {TimeOffset: 15 * time.Second, PlannedVUs: 0},599 {TimeOffset: 16 * time.Second, PlannedVUs: 1},600 {TimeOffset: 20 * time.Second, PlannedVUs: 0},601 {TimeOffset: 23 * time.Second, PlannedVUs: 2},602 {TimeOffset: 26 * time.Second, PlannedVUs: 0},603 {TimeOffset: 28 * time.Second, PlannedVUs: 1},604 {TimeOffset: 29 * time.Second, PlannedVUs: 0},605 {TimeOffset: 32 * time.Second, PlannedVUs: 1},606 },607 },608 {609 et: mustNewExecutionTuple(newExecutionSegmentFromString("2/3:1"), nil),610 expectedSteps: []lib.ExecutionStep{611 {TimeOffset: 0 * time.Second, PlannedVUs: 1},612 {TimeOffset: 1 * time.Second, PlannedVUs: 2},613 {TimeOffset: 4 * time.Second, PlannedVUs: 1},614 {TimeOffset: 7 * time.Second, PlannedVUs: 0},615 {TimeOffset: 8 * time.Second, PlannedVUs: 1},616 {TimeOffset: 11 * time.Second, PlannedVUs: 2},617 {TimeOffset: 12 * time.Second, PlannedVUs: 1},618 {TimeOffset: 15 * time.Second, PlannedVUs: 0},619 {TimeOffset: 16 * time.Second, PlannedVUs: 1},620 {TimeOffset: 20 * time.Second, PlannedVUs: 0},621 {TimeOffset: 23 * time.Second, PlannedVUs: 2},622 {TimeOffset: 26 * time.Second, PlannedVUs: 0},623 {TimeOffset: 28 * time.Second, PlannedVUs: 1},624 {TimeOffset: 29 * time.Second, PlannedVUs: 0},625 {TimeOffset: 32 * time.Second, PlannedVUs: 1},626 },627 },628 {629 et: mustNewExecutionTuple(newExecutionSegmentFromString("0:1/3"), newExecutionSegmentSequenceFromString("0,1/3,2/3,1")),630 expectedSteps: []lib.ExecutionStep{631 {TimeOffset: 0 * time.Second, PlannedVUs: 2},632 {TimeOffset: 5 * time.Second, PlannedVUs: 1},633 {TimeOffset: 10 * time.Second, PlannedVUs: 2},634 {TimeOffset: 13 * time.Second, PlannedVUs: 1},635 {TimeOffset: 18 * time.Second, PlannedVUs: 2},636 {TimeOffset: 20 * time.Second, PlannedVUs: 1},637 {TimeOffset: 23 * time.Second, PlannedVUs: 2},638 {TimeOffset: 26 * time.Second, PlannedVUs: 0},639 {TimeOffset: 27 * time.Second, PlannedVUs: 1},640 {TimeOffset: 30 * time.Second, PlannedVUs: 0},641 {TimeOffset: 31 * time.Second, PlannedVUs: 1},642 {TimeOffset: 34 * time.Second, PlannedVUs: 2},643 },644 },645 {646 et: mustNewExecutionTuple(newExecutionSegmentFromString("1/3:2/3"), newExecutionSegmentSequenceFromString("0,1/3,2/3,1")),647 expectedSteps: []lib.ExecutionStep{648 {TimeOffset: 0 * time.Second, PlannedVUs: 1},649 {TimeOffset: 1 * time.Second, PlannedVUs: 2},650 {TimeOffset: 4 * time.Second, PlannedVUs: 1},651 {TimeOffset: 7 * time.Second, PlannedVUs: 0},652 {TimeOffset: 8 * time.Second, PlannedVUs: 1},653 {TimeOffset: 11 * time.Second, PlannedVUs: 2},654 {TimeOffset: 12 * time.Second, PlannedVUs: 1},655 {TimeOffset: 15 * time.Second, PlannedVUs: 0},656 {TimeOffset: 16 * time.Second, PlannedVUs: 1},657 {TimeOffset: 20 * time.Second, PlannedVUs: 0},658 {TimeOffset: 23 * time.Second, PlannedVUs: 2},659 {TimeOffset: 26 * time.Second, PlannedVUs: 0},660 {TimeOffset: 28 * time.Second, PlannedVUs: 1},661 {TimeOffset: 29 * time.Second, PlannedVUs: 0},662 {TimeOffset: 32 * time.Second, PlannedVUs: 1},663 },664 },665 {666 et: mustNewExecutionTuple(newExecutionSegmentFromString("2/3:1"), newExecutionSegmentSequenceFromString("0,1/3,2/3,1")),667 expectedSteps: []lib.ExecutionStep{668 {TimeOffset: 0 * time.Second, PlannedVUs: 1},669 {TimeOffset: 2 * time.Second, PlannedVUs: 2},670 {TimeOffset: 3 * time.Second, PlannedVUs: 1},671 {TimeOffset: 6 * time.Second, PlannedVUs: 0},672 {TimeOffset: 9 * time.Second, PlannedVUs: 1},673 {TimeOffset: 14 * time.Second, PlannedVUs: 0},674 {TimeOffset: 17 * time.Second, PlannedVUs: 1},675 {TimeOffset: 20 * time.Second, PlannedVUs: 0},676 {TimeOffset: 23 * time.Second, PlannedVUs: 1},677 {TimeOffset: 26 * time.Second, PlannedVUs: 0},678 {TimeOffset: 33 * time.Second, PlannedVUs: 1},679 },680 },681 }682 for _, testCase := range testCases {683 et := testCase.et684 expectedSteps := testCase.expectedSteps685 t.Run(et.String(), func(t *testing.T) {686 t.Parallel()687 rawStepsNoZeroEnd := conf.getRawExecutionSteps(et, false)688 assert.Equal(t, expectedSteps, rawStepsNoZeroEnd)689 })690 }691}692func TestRampingVUsGetRawExecutionStepsCornerCases(t *testing.T) {693 t.Parallel()694 testCases := []struct {695 name string696 expectedSteps []lib.ExecutionStep697 et *lib.ExecutionTuple698 stages []Stage699 start int64700 }{701 {702 name: "going up then down straight away",703 expectedSteps: []lib.ExecutionStep{704 {TimeOffset: 0 * time.Second, PlannedVUs: 2},705 {TimeOffset: 0 * time.Second, PlannedVUs: 5},706 {TimeOffset: 1 * time.Second, PlannedVUs: 4},707 {TimeOffset: 2 * time.Second, PlannedVUs: 3},708 },709 stages: []Stage{710 {Target: null.IntFrom(5), Duration: types.NullDurationFrom(0 * time.Second)},711 {Target: null.IntFrom(3), Duration: types.NullDurationFrom(2 * time.Second)},712 },713 start: 2,714 },715 {716 name: "jump up then go up again",717 expectedSteps: []lib.ExecutionStep{718 {TimeOffset: 0 * time.Second, PlannedVUs: 3},719 {TimeOffset: 1 * time.Second, PlannedVUs: 4},720 {TimeOffset: 2 * time.Second, PlannedVUs: 5},721 },722 stages: []Stage{723 {Target: null.IntFrom(5), Duration: types.NullDurationFrom(2 * time.Second)},724 },725 start: 3,726 },727 {728 name: "up down up down",729 expectedSteps: []lib.ExecutionStep{730 {TimeOffset: 0 * time.Second, PlannedVUs: 0},731 {TimeOffset: 1 * time.Second, PlannedVUs: 1},732 {TimeOffset: 2 * time.Second, PlannedVUs: 2},733 {TimeOffset: 3 * time.Second, PlannedVUs: 1},734 {TimeOffset: 4 * time.Second, PlannedVUs: 0},735 {TimeOffset: 5 * time.Second, PlannedVUs: 1},736 {TimeOffset: 6 * time.Second, PlannedVUs: 2},737 {TimeOffset: 7 * time.Second, PlannedVUs: 1},738 {TimeOffset: 8 * time.Second, PlannedVUs: 0},739 },740 stages: []Stage{741 {Target: null.IntFrom(2), Duration: types.NullDurationFrom(2 * time.Second)},742 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(2 * time.Second)},743 {Target: null.IntFrom(2), Duration: types.NullDurationFrom(2 * time.Second)},744 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(2 * time.Second)},745 },746 },747 {748 name: "up down up down in half",749 expectedSteps: []lib.ExecutionStep{750 {TimeOffset: 0 * time.Second, PlannedVUs: 0},751 {TimeOffset: 1 * time.Second, PlannedVUs: 1},752 {TimeOffset: 4 * time.Second, PlannedVUs: 0},753 {TimeOffset: 5 * time.Second, PlannedVUs: 1},754 {TimeOffset: 8 * time.Second, PlannedVUs: 0},755 },756 et: mustNewExecutionTuple(newExecutionSegmentFromString("0:1/2"), nil),757 stages: []Stage{758 {Target: null.IntFrom(2), Duration: types.NullDurationFrom(2 * time.Second)},759 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(2 * time.Second)},760 {Target: null.IntFrom(2), Duration: types.NullDurationFrom(2 * time.Second)},761 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(2 * time.Second)},762 },763 },764 {765 name: "up down up down in the other half",766 expectedSteps: []lib.ExecutionStep{767 {TimeOffset: 0 * time.Second, PlannedVUs: 0},768 {TimeOffset: 2 * time.Second, PlannedVUs: 1},769 {TimeOffset: 3 * time.Second, PlannedVUs: 0},770 {TimeOffset: 6 * time.Second, PlannedVUs: 1},771 {TimeOffset: 7 * time.Second, PlannedVUs: 0},772 },773 et: mustNewExecutionTuple(newExecutionSegmentFromString("1/2:1"), nil),774 stages: []Stage{775 {Target: null.IntFrom(2), Duration: types.NullDurationFrom(2 * time.Second)},776 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(2 * time.Second)},777 {Target: null.IntFrom(2), Duration: types.NullDurationFrom(2 * time.Second)},778 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(2 * time.Second)},779 },780 },781 {782 name: "up down up down in with nothing",783 expectedSteps: []lib.ExecutionStep{784 {TimeOffset: 0 * time.Second, PlannedVUs: 0},785 },786 et: mustNewExecutionTuple(newExecutionSegmentFromString("2/3:1"), newExecutionSegmentSequenceFromString("0,1/3,2/3,1")),787 stages: []Stage{788 {Target: null.IntFrom(2), Duration: types.NullDurationFrom(2 * time.Second)},789 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(2 * time.Second)},790 {Target: null.IntFrom(2), Duration: types.NullDurationFrom(2 * time.Second)},791 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(2 * time.Second)},792 },793 },794 {795 name: "up down up down in with funky sequence", // panics if there are no localIndex == 0 guards796 expectedSteps: []lib.ExecutionStep{797 {TimeOffset: 0 * time.Second, PlannedVUs: 0},798 {TimeOffset: 1 * time.Second, PlannedVUs: 1},799 {TimeOffset: 4 * time.Second, PlannedVUs: 0},800 {TimeOffset: 5 * time.Second, PlannedVUs: 1},801 {TimeOffset: 8 * time.Second, PlannedVUs: 0},802 },803 et: mustNewExecutionTuple(newExecutionSegmentFromString("0:1/3"), newExecutionSegmentSequenceFromString("0,1/3,1/2,2/3,1")),804 stages: []Stage{805 {Target: null.IntFrom(2), Duration: types.NullDurationFrom(2 * time.Second)},806 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(2 * time.Second)},807 {Target: null.IntFrom(2), Duration: types.NullDurationFrom(2 * time.Second)},808 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(2 * time.Second)},809 },810 },811 {812 name: "strange",813 expectedSteps: []lib.ExecutionStep{814 {TimeOffset: 0 * time.Second, PlannedVUs: 0},815 {TimeOffset: 1 * time.Second, PlannedVUs: 1},816 {TimeOffset: 5 * time.Second, PlannedVUs: 2},817 {TimeOffset: 8 * time.Second, PlannedVUs: 3},818 {TimeOffset: 11 * time.Second, PlannedVUs: 4},819 {TimeOffset: 15 * time.Second, PlannedVUs: 5},820 {TimeOffset: 18 * time.Second, PlannedVUs: 6},821 {TimeOffset: 23 * time.Second, PlannedVUs: 7},822 {TimeOffset: 35 * time.Second, PlannedVUs: 8},823 {TimeOffset: 44 * time.Second, PlannedVUs: 9},824 },825 et: mustNewExecutionTuple(newExecutionSegmentFromString("0:0.3"), newExecutionSegmentSequenceFromString("0,0.3,0.6,0.9,1")),826 stages: []Stage{827 {Target: null.IntFrom(20), Duration: types.NullDurationFrom(20 * time.Second)},828 {Target: null.IntFrom(30), Duration: types.NullDurationFrom(30 * time.Second)},829 },830 },831 {832 name: "more up and down",833 expectedSteps: []lib.ExecutionStep{834 {TimeOffset: 0 * time.Second, PlannedVUs: 0},835 {TimeOffset: 1 * time.Second, PlannedVUs: 1},836 {TimeOffset: 2 * time.Second, PlannedVUs: 2},837 {TimeOffset: 3 * time.Second, PlannedVUs: 3},838 {TimeOffset: 4 * time.Second, PlannedVUs: 4},839 {TimeOffset: 5 * time.Second, PlannedVUs: 5},840 {TimeOffset: 6 * time.Second, PlannedVUs: 4},841 {TimeOffset: 7 * time.Second, PlannedVUs: 3},842 {TimeOffset: 8 * time.Second, PlannedVUs: 2},843 {TimeOffset: 9 * time.Second, PlannedVUs: 1},844 {TimeOffset: 10 * time.Second, PlannedVUs: 0},845 },846 stages: []Stage{847 {Target: null.IntFrom(5), Duration: types.NullDurationFrom(5 * time.Second)},848 {Target: null.IntFrom(0), Duration: types.NullDurationFrom(5 * time.Second)},849 },850 },851 }852 for _, testCase := range testCases {853 testCase := testCase854 conf := NewRampingVUsConfig("test")855 conf.StartVUs = null.IntFrom(testCase.start)856 conf.Stages = testCase.stages857 et := testCase.et858 if et == nil {859 et = mustNewExecutionTuple(nil, nil)860 }861 expectedSteps := testCase.expectedSteps862 t.Run(testCase.name, func(t *testing.T) {863 t.Parallel()864 rawStepsNoZeroEnd := conf.getRawExecutionSteps(et, false)865 assert.Equal(t, expectedSteps, rawStepsNoZeroEnd)866 })867 }868}869func BenchmarkRampingVUsGetRawExecutionSteps(b *testing.B) {870 testCases := []struct {871 seq string872 seg string873 }{874 {},875 {seg: "0:1"},876 {seq: "0,0.3,0.5,0.6,0.7,0.8,0.9,1", seg: "0:0.3"},877 {seq: "0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1", seg: "0:0.1"},878 {seg: "2/5:4/5"},879 {seg: "2235/5213:4/5"}, // just wanted it to be ugly ;D880 }881 stageCases := []struct {882 name string883 stages string884 }{885 {886 name: "normal",887 stages: `[{"duration":"5m", "target":5000},{"duration":"5m", "target":5000},{"duration":"5m", "target":10000},{"duration":"5m", "target":10000}]`,888 }, {889 name: "rollercoaster",890 stages: `[{"duration":"5m", "target":5000},{"duration":"5m", "target":0},891 {"duration":"5m", "target":5000},{"duration":"5m", "target":0},892 {"duration":"5m", "target":5000},{"duration":"5m", "target":0},893 {"duration":"5m", "target":5000},{"duration":"5m", "target":0},894 {"duration":"5m", "target":5000},{"duration":"5m", "target":0},895 {"duration":"5m", "target":5000},{"duration":"5m", "target":0},896 {"duration":"5m", "target":5000},{"duration":"5m", "target":0},897 {"duration":"5m", "target":5000},{"duration":"5m", "target":0},898 {"duration":"5m", "target":5000},{"duration":"5m", "target":0},899 {"duration":"5m", "target":5000},{"duration":"5m", "target":0},900 {"duration":"5m", "target":5000},{"duration":"5m", "target":0}]`,901 },902 }903 for _, tc := range testCases {904 tc := tc905 b.Run(fmt.Sprintf("seq:%s;segment:%s", tc.seq, tc.seg), func(b *testing.B) {906 ess, err := lib.NewExecutionSegmentSequenceFromString(tc.seq)907 require.NoError(b, err)908 segment, err := lib.NewExecutionSegmentFromString(tc.seg)909 require.NoError(b, err)910 if tc.seg == "" {911 segment = nil // specifically for the optimization912 }913 et, err := lib.NewExecutionTuple(segment, &ess)914 require.NoError(b, err)915 for _, stageCase := range stageCases {916 var st []Stage917 require.NoError(b, json.Unmarshal([]byte(stageCase.stages), &st))918 vlvc := RampingVUsConfig{919 Stages: st,920 }921 b.Run(stageCase.name, func(b *testing.B) {922 for i := 0; i < b.N; i++ {923 _ = vlvc.getRawExecutionSteps(et, false)924 }925 })926 }927 })928 }929}930// TODO: delete in favor of lib.generateRandomSequence() after931// https://github.com/k6io/k6/issues/1302 is done (can't import now due to932// import loops...)933func generateRandomSequence(t testing.TB, n, m int64, r *rand.Rand) lib.ExecutionSegmentSequence {934 var err error935 ess := lib.ExecutionSegmentSequence(make([]*lib.ExecutionSegment, n))936 numerators := make([]int64, n)937 var denominator int64938 for i := int64(0); i < n; i++ {939 numerators[i] = 1 + r.Int63n(m)940 denominator += numerators[i]941 }942 from := big.NewRat(0, 1)943 for i := int64(0); i < n; i++ {944 to := new(big.Rat).Add(big.NewRat(numerators[i], denominator), from)945 ess[i], err = lib.NewExecutionSegment(from, to)946 require.NoError(t, err)947 from = to948 }949 return ess950}951func TestSumRandomSegmentSequenceMatchesNoSegment(t *testing.T) {952 t.Parallel()953 const (954 numTests = 10955 maxStages = 10956 minStageDuration = 1 * time.Second957 maxStageDuration = 10 * time.Minute958 maxVUs = 300959 segmentSeqMaxLen = 15960 maxNumerator = 300961 )962 getTestConfig := func(r *rand.Rand, name string) RampingVUsConfig {963 stagesCount := 1 + r.Int31n(maxStages)964 stages := make([]Stage, stagesCount)965 for s := int32(0); s < stagesCount; s++ {966 dur := (minStageDuration + time.Duration(r.Int63n(int64(maxStageDuration-minStageDuration)))).Round(time.Second)967 stages[s] = Stage{Duration: types.NullDurationFrom(dur), Target: null.IntFrom(r.Int63n(maxVUs))}968 }969 c := NewRampingVUsConfig(name)970 c.GracefulRampDown = types.NullDurationFrom(0)971 c.GracefulStop = types.NullDurationFrom(0)972 c.StartVUs = null.IntFrom(r.Int63n(maxVUs))973 c.Stages = stages974 return c975 }976 subtractChildSteps := func(t *testing.T, parent, child []lib.ExecutionStep) {977 t.Logf("subtractChildSteps()")978 for _, step := range child {979 t.Logf(" child planned VUs for time offset %s: %d", step.TimeOffset, step.PlannedVUs)980 }981 sub := uint64(0)982 ci := 0983 for pi, p := range parent {...

Full Screen

Full Screen

NewRampingVUsConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 rampVUsConfig := executor.NewRampingVUsConfig{4 BaseConfig: executor.NewBaseConfig("rampVUs"),5 Stages: []executor.RampingVUsStage{{Duration: types.NullDurationFrom(3 * time.Second), Target: null.NewInt(2, false)}},6 }7 constantLoopingVUsConfig := executor.NewConstantLoopingVUsConfig{8 BaseConfig: executor.NewBaseConfig("constantLoopingVUs"),9 Duration: types.NullDurationFrom(3 * time.Second),10 }11 variableLoopingVUsConfig := executor.NewVariableLoopingVUsConfig{12 BaseConfig: executor.NewBaseConfig("variableLoopingVUs"),13 Stages: []executor.VariableRampingVUsStage{{Duration: types.NullDurationFrom(3 * time.Second), Target: null.NewInt(2, false)}},14 }15 sharedItersConfig := executor.NewSharedIterationsConfig{16 BaseConfig: executor.NewBaseConfig("sharedIters"),17 Iterations: null.IntFrom(2),18 Duration: types.NullDurationFrom(3 * time.Second),19 }

Full Screen

Full Screen

NewRampingVUsConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 engine, err := testutils.NewEngine()4 if err != nil {5 panic(err)6 }7 executorConfig := ramping_vus.NewRampingVUsConfig{8 BaseConfig: executor.BaseConfig{9 },10 GracefulRampDown: types.NullDurationFrom(1 * time.Second),11 StartVUs: null.NewInt(0, false),12 Stages: []ramping_vus.Stage{13 ramping_vus.Stage{Target: 10, Duration: types.NullDurationFrom(5 * time.Second)},14 ramping_vus.Stage{Target: 20, Duration: types.NullDurationFrom(5 * time.Second)},15 ramping_vus.Stage{Target: 0, Duration: types.NullDurationFrom(5 * time.Second)},16 },17 }18 executor, err := ramping_vus.New(executorConfig)19 if err != nil {20 panic(err)21 }22 testPlan := &lib.TestPlan{23 Exec: []lib.ExecutionStep{24 {Exec: executor},25 },26 }27 ctx, cancel := context.WithCancel(context.Background())28 defer cancel()29 engine.Run(ctx, testPlan)30}

Full Screen

Full Screen

NewRampingVUsConfig

Using AI Code Generation

copy

Full Screen

1func ExampleNewRampingVUsConfig() {2 executor := NewRampingVUsConfig()3 fmt.Println(executor)4}5func ExampleNewSharedIterationsConfig() {6 executor := NewSharedIterationsConfig()7 fmt.Println(executor)8}9func ExampleNewConstantArrivalRateConfig() {10 executor := NewConstantArrivalRateConfig()11 fmt.Println(executor)12}13func ExampleNewExternallyControlledConfig() {14 executor := NewExternallyControlledConfig()15 fmt.Println(executor)16}17func ExampleNewPerVUIterationsConfig() {18 executor := NewPerVUIterationsConfig()19 fmt.Println(executor)20}21func ExampleNewSharedArrivalRateConfig() {22 executor := NewSharedArrivalRateConfig()23 fmt.Println(executor)24}25func ExampleNewConstantLoopingVUsConfig() {26 executor := NewConstantLoopingVUsConfig()27 fmt.Println(executor)

Full Screen

Full Screen

NewRampingVUsConfig

Using AI Code Generation

copy

Full Screen

1func main() {2 executor := httpmultibin.NewHTTPMultiBin(t)3 executorURL := executor.GetURL()4 defer executor.Close()5 rampingVUsConfig := lib.NewRampingVUsConfig()6 rampingVUsConfig.StartVUs = null.NewInt(1, false)7 rampingVUsConfig.Stages = []lib.Stage{8 {Duration: types.NullDurationFrom(10 * time.Second), Target: null.NewInt(5, true)},9 }10 runner, err := lib.NewRampingVUs(rampingVUsConfig, executor)11 if err != nil {12 t.Fatal(err)13 }14 engineOut := make(chan stats.SampleContainer, 1000)15 engine := lib.NewEngine(lib.Options{}, engineOut)16 engine.Run(context.Background(), runner, &lib.ExecutionSegmentSequence{Sequence: []*lib.ExecutionSegment{{}}})17}18func main() {19 executor := httpmultibin.NewHTTPMultiBin(t)20 executorURL := executor.GetURL()21 defer executor.Close()22 rampingVUsConfig := lib.NewRampingVUsConfig()23 rampingVUsConfig.StartVUs = null.NewInt(1, false)24 rampingVUsConfig.Stages = []lib.Stage{25 {Duration: types.NullDurationFrom(10 * time.Second), Target: null.NewInt(5, true)},26 }27 runner, err := lib.NewRampingVUs(rampingVUsConfig, executor)28 if err != nil {29 t.Fatal(err)30 }31 engineOut := make(chan stats.SampleContainer, 1000)32 engine := lib.NewEngine(lib.Options{}, engineOut)33 engine.Run(context.Background(), runner, &lib.ExecutionSegmentSequence{Sequence: []*lib.ExecutionSegment{{}}})34}35func main() {36 executor := httpmultibin.NewHTTPMultiBin(t)37 executorURL := executor.GetURL()38 defer executor.Close()39 rampingVUsConfig := lib.NewRampingVUsConfig()40 rampingVUsConfig.StartVUs = null.NewInt(1, false)41 rampingVUsConfig.Stages = []lib.Stage{42 {Duration: types.NullDurationFrom(10

Full Screen

Full Screen

NewRampingVUsConfig

Using AI Code Generation

copy

Full Screen

1func main() {2 executor := NewRampingVUsConfig()3 executor.SetVUs(100)4 executor.SetDuration(10 * time.Second)5 executor.SetGracefulStop(10 * time.Second)6 executor.SetPreAllocatedVUs(100)7 executor.SetStartVUs(10)8 executor.SetStages([]lib.Stage{9 {Target: 10, Duration: 5 * time.Second},10 {Target: 20, Duration: 10 * time.Second},11 {Target: 0, Duration: 5 * time.Second},12 })13 ctx, cancel := context.WithCancel(context.Background())14 defer cancel()15 executor.Run(ctx, nil)16}17func main() {18 executor := NewRampingVUsConfig()19 executor.SetVUs(100)20 executor.SetDuration(10 * time.Second)21 executor.SetGracefulStop(10 * time.Second)22 executor.SetPreAllocatedVUs(100)23 executor.SetStartVUs(10)24 executor.SetStages([]lib.Stage{25 {Target: 10, Duration: 5 * time.Second},26 {Target: 20, Duration: 10 * time.Second},27 {Target: 0, Duration: 5 * time.Second},28 })29 ctx, cancel := context.WithCancel(context.Background())30 defer cancel()31 executor.Run(ctx, nil)32}33func main() {34 executor := NewRampingVUsConfig()35 executor.SetVUs(100)36 executor.SetDuration(10 * time.Second)37 executor.SetGracefulStop(10 * time.Second)38 executor.SetPreAllocatedVUs(100)39 executor.SetStartVUs(10)40 executor.SetStages([]lib.Stage{41 {Target: 10, Duration: 5 * time.Second},42 {Target: 20, Duration: 10 * time.Second},43 {Target: 0, Duration: 5 * time.Second},44 })45 ctx, cancel := context.WithCancel(context.Background())46 defer cancel()47 executor.Run(ctx, nil)48}49func main()

Full Screen

Full Screen

NewRampingVUsConfig

Using AI Code Generation

copy

Full Screen

1func main() {2 executor := &executor{3 executor: executor.NewRampingVUsConfig{4 StartTime: types.NullDurationFrom(1 * time.Second),5 Stages: []executor.RampingVUsConfigStage{6 {Duration: types.NullDurationFrom(10 * time.Second), Target: null.NewInt(20, false)},7 {Duration: types.NullDurationFrom(10 * time.Second), Target: null.NewInt(10, false)},8 {Duration: types.NullDurationFrom(10 * time.Second), Target: null.NewInt(0, true)},9 },10 },11 }12 fmt.Println(executor.executor)13}14{1s [{10s 20} {10s 10} {10s 0}] 0s 0s}

Full Screen

Full Screen

NewRampingVUsConfig

Using AI Code Generation

copy

Full Screen

1func main() {2 executor := httpmultibin.NewHTTPMultiBin()3 executor.RegisterRoutes()4 executor.Register("/vus", func(ctx context.Context, mux *http.ServeMux, _ http.Handler) {5 mux.HandleFunc("/vus", func(w http.ResponseWriter, r *http.Request) {6 if r.Method == http.MethodGet {7 fmt.Fprintf(w, "current VUs: %d", executor.GetVUsCount())8 } else {9 w.WriteHeader(http.StatusMethodNotAllowed)10 }11 })12 })13 executor.Register("/vus/ramp", func(ctx context.Context, mux *http.ServeMux, _ http.Handler) {14 mux.HandleFunc("/vus/ramp", func(w http.ResponseWriter, r *http.Request) {15 if r.Method == http.MethodPost {16 executor.SetVUsCount(10)17 } else {18 w.WriteHeader(http.StatusMethodNotAllowed)19 }20 })21 })22 defer executor.Close()23 engine := NewEngine(executor, EngineOptions{})24 defer engine.Close()25 engine.Run(ctx, nil, nil)26}27func main() {28 executor := httpmultibin.NewHTTPMultiBin()29 executor.RegisterRoutes()30 executor.Register("/vus", func(ctx context.Context, mux *http.ServeMux, _ http.Handler) {31 mux.HandleFunc("/vus", func(w http.ResponseWriter, r *http.Request) {32 if r.Method == http.MethodGet {33 fmt.Fprintf(w, "current VUs: %d", executor.GetVUsCount())34 } else {35 w.WriteHeader(http.StatusMethodNotAllowed)36 }37 })38 })39 executor.Register("/vus/ramp", func(ctx context.Context, mux *http.ServeMux, _ http.Handler) {40 mux.HandleFunc("/vus/ramp", func(w http.ResponseWriter, r *http.Request) {41 if r.Method == http.MethodPost {42 executor.SetVUsCount(10)43 } else {44 w.WriteHeader(http.StatusMethodNotAllowed)45 }46 })47 })48 defer executor.Close()49 engine := NewEngine(executor, EngineOptions{})50 defer engine.Close()51 engine.Run(ctx, nil, nil)52}53func main() {54 executor := httpmultibin.NewHTTPMultiBin()55 executor.RegisterRoutes()56 executor.Register("/vus", func(ctx context.Context, mux *http.ServeMux,

Full Screen

Full Screen

NewRampingVUsConfig

Using AI Code Generation

copy

Full Screen

1func main() {2 stages = append(stages, lib.Stage{Duration: time.Duration(durationMin) * time.Second, Target: vusMin})3 stages = append(stages, lib.Stage{Duration: time.Duration(durationMax) * time.Second, Target: vusMax})4 executor := NewRampingVUsConfig(startVUs, stages)5 fmt.Println(executor)6}7func main() {8 stages = append(stages, lib.Stage{Duration: time.Duration(durationMin) * time.Second, Target: vusMin})9 stages = append(stages, lib.Stage{Duration: time.Duration(durationMax) * time.Second, Target: vusMax})10 executor, err := NewRampingVUs(startVUs, stages)11 if err != nil {12 fmt.Println(err)13 }14 fmt.Println(executor)15}16func main() {17 stages = append(stages, lib.Stage{Duration: time.Duration(durationMin) * time.Second, Target: vusMin})18 stages = append(stages, lib.Stage{Duration: time.Duration(durationMax) * time.Second, Target: vusMax})19 executor, err := NewRampingVUs(startVUs, stages)20 if err != nil {21 fmt.Println(err)22 }23 config := lib.ExecutorConfig{24 StartTime: time.Now(),

Full Screen

Full Screen

NewRampingVUsConfig

Using AI Code Generation

copy

Full Screen

1func main() {2 executor := NewRampingVUsConfig()3 executor.SetVUsMax(10)4 executor.SetDuration("10s")5 executor.SetStartTime("1s")6 executor.SetRampUp("1s")7 executor.SetStages([]Stage{8 Stage{Duration: "2s", Target: 5},9 Stage{Duration: "3s", Target: 10},10 Stage{Duration: "2s", Target: 5},11 })12 fmt.Println(executor)13}14{1s 10s 1s [{2s 5} {3s 10} {2s 5}]}15{1s 10s 1s [{2s 5} {3s 10} {2s 5}]}16Recommended Posts: Go | GetVUsMax() method17Go | GetRampUp() method18Go | GetDuration() method19Go | GetStartTime() method20Go | GetStages() method21Go | SetVUsMax() method22Go | SetDuration() method23Go | SetStartTime() method24Go | SetRampUp() method25Go | SetStages() method26Go | GetVUs() method27Go | GetMaxVUs() method28Go | GetDuration() method29Go | GetStartOffset() method30Go | GetGracefulStop() method31Go | GetEnv() method32Go | GetExec() method33Go | GetExecTimeout() method34Go | GetSetupTimeout() method35Go | GetTeardownTimeout() method36Go | GetSetup() method37Go | GetTeardown() method38Go | GetTags() method39Go | GetSystemTags() method40Go | GetOptions() method41Go | GetIterationTimeout() method42Go | GetThrow() method43Go | GetNoConnectionReuse() method44Go | GetNoVUConnectionReuse() method45Go | GetUserAgent() method46Go | GetBatch() method47Go | GetBatchPerHost() method48Go | GetCookies() method49Go | GetTlsCipherSuites() method50Go | GetTlsVersion() method

Full Screen

Full Screen

NewRampingVUsConfig

Using AI Code Generation

copy

Full Screen

1func main() {2 executor := NewRampingVUsConfig(0, 5, 10, 5)3 executor.Execute()4}5func main() {6 executor := NewConstantVUsConfig(5, 10)7 executor.Execute()8}9func main() {10 executor := NewSharedIterationsConfig(5, 10, 1)11 executor.Execute()12}13func main() {14 executor := NewPerVUIterationsConfig(5, 10, 1)15 executor.Execute()16}17func main() {18 executor := NewConstantArrivalRateConfig(5, 10, 1)19 executor.Execute()20}21func main() {22 executor := NewRampingArrivalRateConfig(0, 5, 10, 5, 1)23 executor.Execute()24}25func main() {26 executor := NewExternallyControlledConfig(5, 10)27 executor.Execute()28}29func main() {30 executor := NewPerVUIterationsConfig(5, 10, 1)31 executor.Execute()32}33func main() {34 executor := NewSharedIterationsConfig(5, 10, 1)35 executor.Execute()36}37func main() {38 executor := NewConstantVUsConfig(5, 10)39 executor.Execute()40}41func main() {42 executor := NewConstantArrivalRateConfig(

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