-
-
Save na--/7105cd97ce76edd4d99c33a8ad38c889 to your computer and use it in GitHub Desktop.
code reuse in k6, you can `k6 run main.js` but also `k6 run script1.js` and `k6 run script2.js`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.1/index.js'; | |
export function setup() { | |
console.log('helpers.js setup()'); | |
return { foo: 'bar' }; | |
} | |
export function teardown(data) { | |
console.log(`helpers.js teardown(${JSON.stringify(data)})`); | |
} | |
export function handleSummary(data) { | |
console.log('helpers.js handleSummary()'); | |
return { | |
'stdout': textSummary(data, { indent: ' ', enableColors: true, }), | |
'raw-summary-data.json': JSON.stringify(data, null, 4), | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export { default as func01 } from './script1.js'; | |
export { default as func02 } from './script2.js'; | |
export { setup, teardown, handleSummary } from './helpers.js'; | |
export let options = { | |
scenarios: { | |
'first_scenario': { | |
executor: 'constant-vus', | |
vus: 2, | |
duration: '10s', | |
exec: 'func01', | |
}, | |
'second_scenario': { | |
executor: 'constant-vus', | |
vus: 3, | |
duration: '15s', | |
exec: 'func02', | |
}, | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { sleep } from "k6"; | |
export { setup, teardown, handleSummary } from './helpers.js'; | |
export default function () { | |
console.log('script1 main'); | |
sleep(1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { sleep } from "k6"; | |
export { setup, teardown, handleSummary } from './helpers.js'; | |
export default function () { | |
console.log('script2 main'); | |
sleep(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's actually what I'm doing right now (running bash script, and then printing all the JSON's, then to CSV) ... thank you very much!
(I just thought maybe I can save some code ... but eventually, the
handleSummary
got me)