How to use TestExecutionInfo method of js Package

Best K6 code snippet using js.TestExecutionInfo

runner_test.go

Source:runner_test.go Github

copy

Full Screen

...2121 }2122 })2123 }2124}2125func TestExecutionInfo(t *testing.T) {2126 t.Parallel()2127 testCases := []struct {2128 name, script, expErr string2129 }{2130 {name: "vu_ok", script: `2131 var exec = require('k6/execution');2132 exports.default = function() {2133 if (exec.vu.idInInstance !== 1) throw new Error('unexpected VU ID: '+exec.vu.idInInstance);2134 if (exec.vu.idInTest !== 10) throw new Error('unexpected global VU ID: '+exec.vu.idInTest);2135 if (exec.vu.iterationInInstance !== 0) throw new Error('unexpected VU iteration: '+exec.vu.iterationInInstance);2136 if (exec.vu.iterationInScenario !== 0) throw new Error('unexpected scenario iteration: '+exec.vu.iterationInScenario);2137 }`},2138 {name: "vu_err", script: `2139 var exec = require('k6/execution');...

Full Screen

Full Screen

execution_test.go

Source:execution_test.go Github

copy

Full Screen

...21func TestMain(m *testing.M) {22 modules.Register("k6/x/execution", New())23 os.Exit(m.Run())24}25func TestExecutionInfoVUSharing(t *testing.T) {26 t.Parallel()27 script := []byte(`28 import exec from 'k6/x/execution';29 import { sleep } from 'k6';30 // The cvus scenario should reuse the two VUs created for the carr scenario.31 export let options = {32 scenarios: {33 carr: {34 executor: 'constant-arrival-rate',35 exec: 'carr',36 rate: 9,37 timeUnit: '0.95s',38 duration: '1s',39 preAllocatedVUs: 2,40 maxVUs: 10,41 gracefulStop: '100ms',42 },43 cvus: {44 executor: 'constant-vus',45 exec: 'cvus',46 vus: 2,47 duration: '1s',48 startTime: '2s',49 gracefulStop: '0s',50 },51 },52 };53 export function cvus() {54 const info = Object.assign({scenario: 'cvus'}, exec.vu);55 console.log(JSON.stringify(info));56 sleep(0.2);57 };58 export function carr() {59 const info = Object.assign({scenario: 'carr'}, exec.vu);60 console.log(JSON.stringify(info));61 };62`)63 logger := logrus.New()64 logger.SetOutput(ioutil.Discard)65 logHook := testutils.SimpleLogrusHook{HookedLevels: []logrus.Level{logrus.InfoLevel}}66 logger.AddHook(&logHook)67 runner, err := js.New(68 logger,69 &loader.SourceData{70 URL: &url.URL{Path: "/script.js"},71 Data: script,72 },73 nil,74 lib.RuntimeOptions{},75 )76 require.NoError(t, err)77 ctx, cancel, execScheduler, samples := newTestExecutionScheduler(t, runner, logger, lib.Options{})78 defer cancel()79 type vuStat struct {80 iteration uint6481 scIter map[string]uint6482 }83 vuStats := map[uint64]*vuStat{}84 type logEntry struct {85 IdInInstance uint6486 Scenario string87 IterationInInstance uint6488 IterationInScenario uint6489 }90 errCh := make(chan error, 1)91 go func() { errCh <- execScheduler.Run(ctx, ctx, samples) }()92 select {93 case err := <-errCh:94 require.NoError(t, err)95 entries := logHook.Drain()96 assert.InDelta(t, 20, len(entries), 2)97 le := &logEntry{}98 for _, entry := range entries {99 err = json.Unmarshal([]byte(entry.Message), le)100 require.NoError(t, err)101 assert.Contains(t, []uint64{1, 2}, le.IdInInstance)102 if _, ok := vuStats[le.IdInInstance]; !ok {103 vuStats[le.IdInInstance] = &vuStat{0, make(map[string]uint64)}104 }105 if le.IterationInInstance > vuStats[le.IdInInstance].iteration {106 vuStats[le.IdInInstance].iteration = le.IterationInInstance107 }108 if le.IterationInScenario > vuStats[le.IdInInstance].scIter[le.Scenario] {109 vuStats[le.IdInInstance].scIter[le.Scenario] = le.IterationInScenario110 }111 }112 require.Len(t, vuStats, 2)113 // Both VUs should complete 10 iterations each globally, but 5114 // iterations each per scenario (iterations are 0-based)115 for _, v := range vuStats {116 assert.Equal(t, uint64(9), v.iteration)117 assert.Equal(t, uint64(4), v.scIter["cvus"])118 assert.Equal(t, uint64(4), v.scIter["carr"])119 }120 case <-time.After(10 * time.Second):121 t.Fatal("timed out")122 }123}124func TestExecutionInfoScenarioIter(t *testing.T) {125 t.Parallel()126 script := []byte(`127 import exec from 'k6/x/execution';128 // The pvu scenario should reuse the two VUs created for the carr scenario.129 export let options = {130 scenarios: {131 carr: {132 executor: 'constant-arrival-rate',133 exec: 'carr',134 rate: 9,135 timeUnit: '0.95s',136 duration: '1s',137 preAllocatedVUs: 2,138 maxVUs: 10,139 gracefulStop: '100ms',140 },141 pvu: {142 executor: 'per-vu-iterations',143 exec: 'pvu',144 vus: 2,145 iterations: 5,146 startTime: '2s',147 gracefulStop: '100ms',148 },149 },150 };151 export function pvu() {152 const info = Object.assign({VUID: __VU}, exec.scenario);153 console.log(JSON.stringify(info));154 }155 export function carr() {156 const info = Object.assign({VUID: __VU}, exec.scenario);157 console.log(JSON.stringify(info));158 };159`)160 logger := logrus.New()161 logger.SetOutput(ioutil.Discard)162 logHook := testutils.SimpleLogrusHook{HookedLevels: []logrus.Level{logrus.InfoLevel}}163 logger.AddHook(&logHook)164 runner, err := js.New(165 logger,166 &loader.SourceData{167 URL: &url.URL{Path: "/script.js"},168 Data: script,169 },170 nil,171 lib.RuntimeOptions{},172 )173 require.NoError(t, err)174 ctx, cancel, execScheduler, samples := newTestExecutionScheduler(t, runner, logger, lib.Options{})175 defer cancel()176 errCh := make(chan error, 1)177 go func() { errCh <- execScheduler.Run(ctx, ctx, samples) }()178 scStats := map[string]uint64{}179 type logEntry struct {180 Name string181 IterationInInstance, VUID uint64182 }183 select {184 case err := <-errCh:185 require.NoError(t, err)186 entries := logHook.Drain()187 require.Len(t, entries, 20)188 le := &logEntry{}189 for _, entry := range entries {190 err = json.Unmarshal([]byte(entry.Message), le)191 require.NoError(t, err)192 assert.Contains(t, []uint64{1, 2}, le.VUID)193 if le.IterationInInstance > scStats[le.Name] {194 scStats[le.Name] = le.IterationInInstance195 }196 }197 require.Len(t, scStats, 2)198 // The global per scenario iteration count should be 9 (iterations199 // start at 0), despite VUs being shared or more than 1 being used.200 for _, v := range scStats {201 assert.Equal(t, uint64(9), v)202 }203 case <-time.After(10 * time.Second):204 t.Fatal("timed out")205 }206}207// Ensure that scenario iterations returned from k6/x/execution are208// stable during the execution of an iteration.209func TestSharedIterationsStable(t *testing.T) {210 t.Parallel()211 script := []byte(`212 import { sleep } from 'k6';213 import exec from 'k6/x/execution';214 export let options = {215 scenarios: {216 test: {217 executor: 'shared-iterations',218 vus: 50,219 iterations: 50,220 },221 },222 };223 export default function () {224 sleep(1);225 console.log(JSON.stringify(Object.assign({VUID: __VU}, exec.scenario)));226 }227`)228 logger := logrus.New()229 logger.SetOutput(ioutil.Discard)230 logHook := testutils.SimpleLogrusHook{HookedLevels: []logrus.Level{logrus.InfoLevel}}231 logger.AddHook(&logHook)232 runner, err := js.New(233 logger,234 &loader.SourceData{235 URL: &url.URL{Path: "/script.js"},236 Data: script,237 },238 nil,239 lib.RuntimeOptions{},240 )241 require.NoError(t, err)242 ctx, cancel, execScheduler, samples := newTestExecutionScheduler(t, runner, logger, lib.Options{})243 defer cancel()244 errCh := make(chan error, 1)245 go func() { errCh <- execScheduler.Run(ctx, ctx, samples) }()246 expIters := [50]int64{}247 for i := 0; i < 50; i++ {248 expIters[i] = int64(i)249 }250 gotLocalIters, gotGlobalIters := []int64{}, []int64{}251 type logEntry struct{ IterationInInstance, IterationInTest int64 }252 select {253 case err := <-errCh:254 require.NoError(t, err)255 entries := logHook.Drain()256 require.Len(t, entries, 50)257 le := &logEntry{}258 for _, entry := range entries {259 err = json.Unmarshal([]byte(entry.Message), le)260 require.NoError(t, err)261 require.Equal(t, le.IterationInInstance, le.IterationInTest)262 gotLocalIters = append(gotLocalIters, le.IterationInInstance)263 gotGlobalIters = append(gotGlobalIters, le.IterationInTest)264 }265 assert.ElementsMatch(t, expIters, gotLocalIters)266 assert.ElementsMatch(t, expIters, gotGlobalIters)267 case <-time.After(5 * time.Second):268 t.Fatal("timed out")269 }270}271func TestExecutionInfo(t *testing.T) {272 t.Parallel()273 testCases := []struct {274 name, script, expErr string275 }{276 {name: "vu_ok", script: `277 var exec = require('k6/x/execution');278 exports.default = function() {279 if (exec.vu.idInInstance !== 1) throw new Error('unexpected VU ID: '+exec.vu.idInInstance);280 if (exec.vu.idInTest !== 10) throw new Error('unexpected global VU ID: '+exec.vu.idInTest);281 if (exec.vu.iterationInInstance !== 0) throw new Error('unexpected VU iteration: '+exec.vu.iterationInInstance);282 if (exec.vu.iterationInScenario !== 0) throw new Error('unexpected scenario iteration: '+exec.vu.iterationInScenario);283 }`},284 {name: "vu_err", script: `285 var exec = require('k6/x/execution');...

Full Screen

Full Screen

TestExecutionInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 vm := otto.New()4 vm.Set("print", func(call otto.FunctionCall) otto.Value {5 fmt.Println(call.Argument(0))6 return otto.Value{}7 })8 vm.Run(`9 var js = require("TestExecutionInfo");10 js.TestExecutionInfo();11}12var TestExecutionInfo = function() {13 console.log('TestExecutionInfo method called');14};15module.exports = {16};17Your name to display (optional):

Full Screen

Full Screen

TestExecutionInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 vm := otto.New()4 vm.Run(`5 function TestExecutionInfo() {6 console.log("TestExecutionInfo")7 }8 value, err := vm.Call("TestExecutionInfo", nil)9 if err != nil {10 panic(err)11 }12 fmt.Println(value.String())13}14import (15func main() {16 vm := otto.New()17 vm.Run(`18 function TestExecutionInfo() {19 console.log("TestExecutionInfo")20 }21 value, err := vm.Call("TestExecutionInfo", nil)22 if err != nil {23 panic(err)24 }25 fmt.Println(value.String())26}27import (28func main() {29 vm := otto.New()30 vm.Run(`31 function TestExecutionInfo() {32 console.log("TestExecutionInfo")33 }34 value, err := vm.Call("TestExecutionInfo", nil)35 if err != nil {36 panic(err)37 }38 fmt.Println(value.String())39}40import (41func main() {42 vm := otto.New()43 vm.Run(`44 function TestExecutionInfo() {45 console.log("TestExecutionInfo")46 }47 value, err := vm.Call("TestExecutionInfo", nil)48 if err != nil {49 panic(err)50 }51 fmt.Println(value.String())52}53import (54func main() {

Full Screen

Full Screen

TestExecutionInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 js := otto.New()4 js.Set("print", func(call otto.FunctionCall) otto.Value {5 fmt.Println(call.Argument(0).String())6 return otto.UndefinedValue()7 })8 js.Set("log", func(call otto.FunctionCall) otto.Value {9 fmt.Println(call.Argument(0).String())10 return otto.UndefinedValue()11 })12 js.Set("logError", func(call otto.FunctionCall) otto.Value {13 fmt.Println(call.Argument(0).String())14 return otto.UndefinedValue()15 })16 js.Set("logWarning", func(call otto.FunctionCall) otto.Value {17 fmt.Println(call.Argument(0).String())18 return otto.UndefinedValue()19 })20 js.Set("logInfo", func(call otto.FunctionCall) otto.Value {21 fmt.Println(call.Argument(0).String())22 return otto.UndefinedValue()23 })24 js.Set("logDebug", func(call otto.FunctionCall) otto.Value {25 fmt.Println(call.Argument(0).String())26 return otto.UndefinedValue()27 })28 js.Set("logTrace", func(call otto.FunctionCall) otto.Value {29 fmt.Println(call.Argument(0).String())30 return otto.UndefinedValue()31 })32 js.Set("logFatal", func(call otto.FunctionCall) otto.Value {33 fmt.Println(call.Argument(0).String())34 return otto.UndefinedValue()35 })36 js.Set("logPanic", func(call otto.FunctionCall) otto.Value {37 fmt.Println(call.Argument(0).String())38 return otto.UndefinedValue()39 })40 js.Set("logNotice", func(call otto.FunctionCall) otto.Value {41 fmt.Println(call.Argument(0).String())42 return otto.UndefinedValue()43 })44 vm := otto.New()45 vm.Set("vm", js)46 vm.Set("log", log.Println)47 vm.Set("logError", log.Println)48 vm.Set("logWarning", log.Println)49 vm.Set("logInfo", log.Println)50 vm.Set("logDebug", log.Println)51 vm.Set("logTrace", log.Println)52 vm.Set("logFatal", log.Println)

Full Screen

Full Screen

TestExecutionInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 vm := otto.New()4 vm.Set("fmt", fmt)5 _, err := vm.Run(`6 var js = require('TestExecutionInfo');7 js.TestExecutionInfo();8 if err != nil {9 fmt.Println(err)10 }11}12var TestExecutionInfo = function() {13 var execInfo = Java.type("com.test.TestExecutionInfo");14 execInfo.TestExecutionInfo();15};16package com.test;17import com.test.TestExecutionInfo;18public class TestExecutionInfo {19 public static void TestExecutionInfo() {20 System.out.println("TestExecutionInfo called");21 }22}

Full Screen

Full Screen

TestExecutionInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 vm := otto.New()4 _, err := vm.Run(`var js = require('js')`)5 if err != nil {6 fmt.Println("Error occured: ", err)7 }8 vm.Set("myFunc", func(call otto.FunctionCall) otto.Value {9 fmt.Println("myFunc called!")10 return otto.Value{}11 })12 vm.Set("myFunc2", func(call otto.FunctionCall) otto.Value {13 fmt.Println("myFunc2 called!")14 return otto.Value{}15 })16 _, err = vm.Run(`17 js.TestExecutionInfo(myFunc, myFunc2);18 if err != nil {19 fmt.Println("Error occured: ", err)20 }21}22Now, I am trying to do the same thing in C++ using V8. I am using the V8 C++ API to do this. I am able to call the TestExecutionInfo method of the js class, but the callback functions are not being called. I am using the v8::FunctionTemplate::New() method to create the functions. Below is the code I am using:23using namespace std;24using namespace v8;25void myFunc(const FunctionCallbackInfo<Value>& args) {26 Isolate* isolate = args.GetIsolate();27 HandleScope scope(isolate);28 cout << "myFunc called!" << endl;29}30void myFunc2(const FunctionCallbackInfo<Value>& args) {31 Isolate* isolate = args.GetIsolate();32 HandleScope scope(isolate);33 cout << "myFunc2 called!" << endl;34}35int main() {36 V8::InitializeICUDefaultLocation("");37 V8::InitializeExternalStartupData("");38 Platform* platform = platform::NewDefaultPlatform();39 V8::InitializePlatform(platform);40 V8::Initialize();41 Isolate::CreateParams create_params;42 create_params.array_buffer_allocator = ArrayBuffer::Allocator::NewDefaultAllocator();43 Isolate* isolate = Isolate::New(create_params);44 {45 Isolate::Scope isolate_scope(isolate);

Full Screen

Full Screen

TestExecutionInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 vm := otto.New()4 vm.Set("fmt", fmt)5 vm.Run(`6 var js = require('js');

Full Screen

Full Screen

TestExecutionInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 testExecutionInfo()5}6func testExecutionInfo() {7 js.Global().Get("console").Call("log", "testExecutionInfo")8}9import (10func main() {11 fmt.Println("Hello, playground")12 testExecutionInfo()13}14func testExecutionInfo() {15 js.Global().Get("console").Call("log", "testExecutionInfo")16}17import (18func main() {19 fmt.Println("Hello, playground")20 testExecutionInfo()21}22func testExecutionInfo() {23 js.Global().Get("console").Call("log", "testExecutionInfo")24}25import (26func main() {27 fmt.Println("Hello, playground")28 testExecutionInfo()29}30func testExecutionInfo() {31 js.Global().Get("console").Call("log", "testExecutionInfo")32}33import (34func main() {35 fmt.Println("Hello, playground")36 testExecutionInfo()37}38func testExecutionInfo() {39 js.Global().Get("console").Call("log", "testExecutionInfo")40}41import (42func main() {43 fmt.Println("Hello, playground")44 testExecutionInfo()45}46func testExecutionInfo() {47 js.Global().Get("console").Call("log", "testExecutionInfo")48}

Full Screen

Full Screen

TestExecutionInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 TestExecutionInfo()5}6func TestExecutionInfo() {7 fmt.Println("TestExecutionInfo method")8 pc, file, line, ok := runtime.Caller(0)9 fmt.Println("pc=", pc)10 fmt.Println("file=", file)11 fmt.Println("line=", line)12 fmt.Println("ok=", ok)13 fmt.Println("runtime.Caller=", runtime.Caller(0))14 fmt.Println("runtime.Caller=", runtime.Caller(1))15 fmt.Println("runtime.Caller=", runtime.Caller(2))16 fmt.Println("runtime.Caller=", runtime.Caller(3))17 fmt.Println("runtime.Caller=", runtime.Caller(4))18 fmt.Println("runtime.Caller=", runtime.Caller(5))19 fmt.Println("runtime.Caller=", runtime.Caller(6))20 fmt.Println("runtime.Caller=", runtime.Caller(7))21 fmt.Println("runtime.Caller=", runtime.Caller(8))22 fmt.Println("runtime.Caller=", runtime.Caller(9))23 fmt.Println("runtime.Caller=", runtime.Caller(10))24 fmt.Println("runtime.Caller=", runtime.Caller(11))25 fmt.Println("runtime.Caller=", runtime.Caller(12))26 fmt.Println("runtime.Caller=", runtime.Caller(13))27 fmt.Println("runtime.Caller=", runtime.Caller(14))28 fmt.Println("runtime.Caller=", runtime.Caller(15))29 fmt.Println("runtime.Caller=", runtime.Caller(16))30 fmt.Println("runtime.Caller=", runtime.Caller(17))31 fmt.Println("runtime.Caller=", runtime.Caller(18))32 fmt.Println("runtime.Caller=", runtime.Caller(19))33 fmt.Println("runtime.Caller=", runtime.Caller(20))34 fmt.Println("runtime.Caller=", runtime.Caller(21))35 fmt.Println("runtime.Caller=", runtime.Caller(22))36 fmt.Println("runtime.Caller=", runtime.Caller(23))37 fmt.Println("runtime.Caller=", runtime.Caller(24))38 fmt.Println("runtime.Caller=", runtime.Caller(25))39 fmt.Println("runtime.Caller=", runtime.Caller(26))40 fmt.Println("runtime.Caller=", runtime.Caller(27))41 fmt.Println("runtime.Caller=", runtime.Caller(28))42 fmt.Println("runtime.Caller=", runtime.Caller(29))43 fmt.Println("runtime.Caller=", runtime.Caller(

Full Screen

Full Screen

TestExecutionInfo

Using AI Code Generation

copy

Full Screen

1import (2func init() {3 gauge.Step("Test Execution Info", testExecutionInfo)4 gauge.Step("Test Step Execution Info", testStepExecutionInfo)5}6func TearDown() {7}8func SuiteTearDown() {9}10func SuiteSetup() {11}12func testExecutionInfo() {13 testExecutionInfo := testsuit.TestExecutionInfo()14 testName := testExecutionInfo.Name()15 testStatus := testExecutionInfo.Status()16 testDuration := testExecutionInfo.Duration()17 testStartTime := testExecutionInfo.StartTime()

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