How to use mustNewExecutionTuple method of executor Package

Best K6 code snippet using executor.mustNewExecutionTuple

ramping_arrival_rate_test.go

Source:ramping_arrival_rate_test.go Github

copy

Full Screen

...287 for range engineOut {288 // discard289 }290 }()291 es := lib.NewExecutionState(lib.Options{}, mustNewExecutionTuple(nil, nil), uint64(tc.prealloc.Int64), uint64(tc.prealloc.Int64))292 var count int64293 runner := simpleRunner(func(ctx context.Context) error {294 atomic.AddInt64(&count, 1)295 return nil296 })297 // an high target to get the highest rate298 target := int64(1e9)299 ctx, cancel, executor, _ := setupExecutor(300 b, &RampingArrivalRateConfig{301 TimeUnit: types.NullDurationFrom(1 * time.Second),302 Stages: []Stage{303 {304 Duration: types.NullDurationFrom(0),305 Target: null.IntFrom(target),306 },307 {308 Duration: types.NullDurationFrom(5 * time.Second),309 Target: null.IntFrom(target),310 },311 },312 PreAllocatedVUs: tc.prealloc,313 MaxVUs: tc.prealloc,314 },315 es, runner)316 defer cancel()317 b.ResetTimer()318 start := time.Now()319 registry := metrics.NewRegistry()320 builtinMetrics := metrics.RegisterBuiltinMetrics(registry)321 err := executor.Run(ctx, engineOut, builtinMetrics)322 took := time.Since(start)323 assert.NoError(b, err)324 iterations := float64(atomic.LoadInt64(&count))325 b.ReportMetric(0, "ns/op")326 b.ReportMetric(iterations/took.Seconds(), "iterations/s")327 })328 }329}330func mustNewExecutionTuple(seg *lib.ExecutionSegment, seq *lib.ExecutionSegmentSequence) *lib.ExecutionTuple {331 et, err := lib.NewExecutionTuple(seg, seq)332 if err != nil {333 panic(err)334 }335 return et336}337func TestRampingArrivalRateCal(t *testing.T) {338 t.Parallel()339 var (340 defaultTimeUnit = time.Second341 getConfig = func() RampingArrivalRateConfig {342 return RampingArrivalRateConfig{343 StartRate: null.IntFrom(0),344 Stages: []Stage{ // TODO make this even bigger and longer .. will need more time345 {346 Duration: types.NullDurationFrom(time.Second * 5),347 Target: null.IntFrom(1),348 },349 {350 Duration: types.NullDurationFrom(time.Second * 1),351 Target: null.IntFrom(1),352 },353 {354 Duration: types.NullDurationFrom(time.Second * 5),355 Target: null.IntFrom(0),356 },357 },358 }359 }360 )361 testCases := []struct {362 expectedTimes []time.Duration363 et *lib.ExecutionTuple364 timeUnit time.Duration365 }{366 {367 expectedTimes: []time.Duration{time.Millisecond * 3162, time.Millisecond * 4472, time.Millisecond * 5500, time.Millisecond * 6527, time.Millisecond * 7837, time.Second * 11},368 et: mustNewExecutionTuple(nil, nil),369 },370 {371 expectedTimes: []time.Duration{time.Millisecond * 4472, time.Millisecond * 7837},372 et: mustNewExecutionTuple(newExecutionSegmentFromString("0:1/3"), nil),373 },374 {375 expectedTimes: []time.Duration{time.Millisecond * 4472, time.Millisecond * 7837},376 et: mustNewExecutionTuple(newExecutionSegmentFromString("0:1/3"), newExecutionSegmentSequenceFromString("0,1/3,1")),377 },378 {379 expectedTimes: []time.Duration{time.Millisecond * 4472, time.Millisecond * 7837},380 et: mustNewExecutionTuple(newExecutionSegmentFromString("1/3:2/3"), nil),381 },382 {383 expectedTimes: []time.Duration{time.Millisecond * 4472, time.Millisecond * 7837},384 et: mustNewExecutionTuple(newExecutionSegmentFromString("2/3:1"), nil),385 },386 {387 expectedTimes: []time.Duration{time.Millisecond * 3162, time.Millisecond * 6527},388 et: mustNewExecutionTuple(newExecutionSegmentFromString("0:1/3"), newExecutionSegmentSequenceFromString("0,1/3,2/3,1")),389 },390 {391 expectedTimes: []time.Duration{time.Millisecond * 4472, time.Millisecond * 7837},392 et: mustNewExecutionTuple(newExecutionSegmentFromString("1/3:2/3"), newExecutionSegmentSequenceFromString("0,1/3,2/3,1")),393 },394 {395 expectedTimes: []time.Duration{time.Millisecond * 5500, time.Millisecond * 11000},396 et: mustNewExecutionTuple(newExecutionSegmentFromString("2/3:1"), newExecutionSegmentSequenceFromString("0,1/3,2/3,1")),397 },398 {399 expectedTimes: []time.Duration{400 time.Millisecond * 1825, time.Millisecond * 2581, time.Millisecond * 3162, time.Millisecond * 3651, time.Millisecond * 4082, time.Millisecond * 4472,401 time.Millisecond * 4830, time.Millisecond * 5166, time.Millisecond * 5499, time.Millisecond * 5833, time.Millisecond * 6169, time.Millisecond * 6527,402 time.Millisecond * 6917, time.Millisecond * 7348, time.Millisecond * 7837, time.Millisecond * 8418, time.Millisecond * 9174, time.Millisecond * 10999,403 },404 et: mustNewExecutionTuple(nil, nil),405 timeUnit: time.Second / 3, // three times as fast406 },407 // TODO: extend more408 }409 for testNum, testCase := range testCases {410 et := testCase.et411 expectedTimes := testCase.expectedTimes412 config := getConfig()413 config.TimeUnit = types.NewNullDuration(testCase.timeUnit, true)414 if testCase.timeUnit == 0 {415 config.TimeUnit = types.NewNullDuration(defaultTimeUnit, true)416 }417 t.Run(fmt.Sprintf("testNum %d - %s timeunit %s", testNum, et, config.TimeUnit), func(t *testing.T) {418 t.Parallel()419 ch := make(chan time.Duration)420 go config.cal(et, ch)421 changes := make([]time.Duration, 0, len(expectedTimes))422 for c := range ch {423 changes = append(changes, c)424 }425 assert.Equal(t, len(expectedTimes), len(changes))426 for i, expectedTime := range expectedTimes {427 require.True(t, i < len(changes))428 change := changes[i]429 assert.InEpsilon(t, expectedTime, change, 0.001, "Expected around %s, got %s", expectedTime, change)430 }431 })432 }433}434func BenchmarkCal(b *testing.B) {435 for _, t := range []time.Duration{436 time.Second, time.Minute,437 } {438 t := t439 b.Run(t.String(), func(b *testing.B) {440 config := RampingArrivalRateConfig{441 TimeUnit: types.NullDurationFrom(time.Second),442 StartRate: null.IntFrom(50),443 Stages: []Stage{444 {445 Duration: types.NullDurationFrom(t),446 Target: null.IntFrom(49),447 },448 {449 Duration: types.NullDurationFrom(t),450 Target: null.IntFrom(50),451 },452 },453 }454 et := mustNewExecutionTuple(nil, nil)455 b.ResetTimer()456 b.RunParallel(func(pb *testing.PB) {457 for pb.Next() {458 ch := make(chan time.Duration, 20)459 go config.cal(et, ch)460 for c := range ch {461 _ = c462 }463 }464 })465 })466 }467}468func BenchmarkCalRat(b *testing.B) {469 for _, t := range []time.Duration{470 time.Second, time.Minute,471 } {472 t := t473 b.Run(t.String(), func(b *testing.B) {474 config := RampingArrivalRateConfig{475 TimeUnit: types.NullDurationFrom(time.Second),476 StartRate: null.IntFrom(50),477 Stages: []Stage{478 {479 Duration: types.NullDurationFrom(t),480 Target: null.IntFrom(49),481 },482 {483 Duration: types.NullDurationFrom(t),484 Target: null.IntFrom(50),485 },486 },487 }488 et := mustNewExecutionTuple(nil, nil)489 b.ResetTimer()490 b.RunParallel(func(pb *testing.PB) {491 for pb.Next() {492 ch := make(chan time.Duration, 20)493 go config.calRat(et, ch)494 for c := range ch {495 _ = c496 }497 }498 })499 })500 }501}502func TestCompareCalImplementation(t *testing.T) {503 t.Parallel()504 // This test checks that the cal and calRat implementation get roughly similar numbers505 // in my experiment the difference is 1(nanosecond) in 7 case for the whole test506 // the duration is 1 second for each stage as calRat takes way longer - a longer better test can507 // be done when/if it's performance is improved508 config := RampingArrivalRateConfig{509 TimeUnit: types.NullDurationFrom(time.Second),510 StartRate: null.IntFrom(0),511 Stages: []Stage{512 {513 Duration: types.NullDurationFrom(1 * time.Second),514 Target: null.IntFrom(200),515 },516 {517 Duration: types.NullDurationFrom(1 * time.Second),518 Target: null.IntFrom(200),519 },520 {521 Duration: types.NullDurationFrom(1 * time.Second),522 Target: null.IntFrom(2000),523 },524 {525 Duration: types.NullDurationFrom(1 * time.Second),526 Target: null.IntFrom(2000),527 },528 {529 Duration: types.NullDurationFrom(1 * time.Second),530 Target: null.IntFrom(300),531 },532 {533 Duration: types.NullDurationFrom(1 * time.Second),534 Target: null.IntFrom(300),535 },536 {537 Duration: types.NullDurationFrom(1 * time.Second),538 Target: null.IntFrom(1333),539 },540 {541 Duration: types.NullDurationFrom(1 * time.Second),542 Target: null.IntFrom(1334),543 },544 {545 Duration: types.NullDurationFrom(1 * time.Second),546 Target: null.IntFrom(1334),547 },548 },549 }550 et := mustNewExecutionTuple(nil, nil)551 chRat := make(chan time.Duration, 20)552 ch := make(chan time.Duration, 20)553 go config.calRat(et, chRat)554 go config.cal(et, ch)555 count := 0556 var diff int557 for c := range ch {558 count++559 cRat := <-chRat560 if !assert.InDelta(t, c, cRat, 1, "%d", count) {561 diff++562 }563 }564 require.Equal(t, 0, diff)...

Full Screen

Full Screen

mustNewExecutionTuple

Using AI Code Generation

copy

Full Screen

1func main() {2}3func main() {4}5func main() {6}

Full Screen

Full Screen

mustNewExecutionTuple

Using AI Code Generation

copy

Full Screen

1import (2type Executor struct {3}4func (e *Executor) mustNewExecutionTuple() (*ExecutionTuple, error) {5 return &ExecutionTuple{}, nil6}7type ExecutionTuple struct {8}9func main() {10 _, err := e.mustNewExecutionTuple()11 if err != nil {12 fmt.Println("Error is not nil")13 } else {14 fmt.Println("Error is nil")15 }16}

Full Screen

Full Screen

mustNewExecutionTuple

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 db := ethdb.NewMemDatabase()4 trie, _ := trie.New(common.Hash{}, trie.NewDatabase(db))5 state, _ := state.New(common.Hash{}, state.NewDatabase(db))6 block := &types.Block{7 Header: &types.Header{8 Number: new(big.Int).SetUint64(1),9 Root: trie.Hash(),10 },11 Transactions: []*types.Transaction{12 types.NewTransaction(0, common.HexToAddress("0x1"), new(big.Int), 0, new(big.Int), nil),13 },14 }15 receipts := []*types.Receipt{16 {17 PostState: state.IntermediateRoot(true),18 },19 }20 chain := &core.BlockChain{21 CurrentBlock: func() *types.Block {22 },23 GetHeader: func(hash common.Hash, number uint64) *types.Header {24 return block.Header()25 },26 GetBlock: func(hash common.Hash, number uint64) *types.Block {27 },28 GetReceiptsByHash: func(hash common.Hash) types.Receipts {29 },30 }31 engine := ethash.NewFaker()32 executor := core.NewStateTransition(chain, engine, nil)33 executionTuple := executor.MustNewExecutionTuple(block, receipts)34 fmt.Println(executionTuple)35}36{1 0x6c9e1

Full Screen

Full Screen

mustNewExecutionTuple

Using AI Code Generation

copy

Full Screen

1import (2type Executor struct {3 executorFunction func([]interface{}) interface{}4}5func mustNewExecutionTuple(name string, executorType string, executorFunction func([]interface{}) interface{}, inputTupleType reflect.Type, outputTupleType reflect.Type) *Executor {6 return &Executor{7 }8}9func main() {10 executor = mustNewExecutionTuple("Executor", "ExecutorType", func(input []interface{}) interface{} {11 }, reflect.TypeOf([]interface{}{0}), reflect.TypeOf(0))12 fmt.Println(executor)13}14&{Executor ExecutorType 0x10c1f00 [3]int [1]int}15cannot use func([]interface {}) interface {} literal (type func([]interface {}) interface {}) as type func([]interface {}) interface {} in field value

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