-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2522 from artilleryio/feat/async-hooks
- Loading branch information
Showing
15 changed files
with
179 additions
and
68 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const tap = require('tap'); | ||
const { execute, generateTmpReportPath } = require('../cli/_helpers.js'); | ||
const fs = require('fs'); | ||
|
||
let reportFilePath; | ||
tap.beforeEach(async (t) => { | ||
reportFilePath = generateTmpReportPath(t.name, 'json'); | ||
}); | ||
|
||
tap.test('async hooks with ESM', async (t) => { | ||
const [exitCode, output] = await execute([ | ||
'run', | ||
'-o', | ||
`${reportFilePath}`, | ||
'test/scripts/scenario-async-esm-hooks/test.yml' | ||
]); | ||
|
||
t.equal(exitCode, 0, 'CLI should exit with code 0'); | ||
t.ok( | ||
output.stdout.includes('Got context using lodash: true'), | ||
'Should be able to use lodash in a scenario to get context' | ||
); | ||
const json = JSON.parse(fs.readFileSync(reportFilePath, 'utf8')); | ||
|
||
console.log(output); | ||
|
||
t.equal( | ||
json.aggregate.counters['http.codes.200'], | ||
10, | ||
'Should have made 10 requests' | ||
); | ||
|
||
t.equal( | ||
json.aggregate.counters['hey_from_esm'], | ||
10, | ||
'Should have emitted 10 custom metrics from ts processor' | ||
); | ||
|
||
t.equal( | ||
json.aggregate.counters['errors.error_from_async_hook'], | ||
10, | ||
'Should have emitted 10 errors from an exception in an async hook' | ||
); | ||
|
||
t.equal( | ||
json.aggregate.counters['vusers.failed'], | ||
10, | ||
'Should have no completed VUs' | ||
); | ||
}); |
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
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
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
11 changes: 11 additions & 0 deletions
11
packages/artillery/test/scripts/scenario-async-esm-hooks/helpers.mjs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import _ from 'lodash'; | ||
|
||
export const emitCustomMetric = async (context, ee) => { | ||
const isESM = _.get(context, 'vars.isESM'); | ||
console.log(`Got context using lodash: ${JSON.stringify(isESM)}`); | ||
ee.emit('counter', 'hey_from_esm', 1); | ||
}; | ||
|
||
export const hookThatThrows = async (context, ee) => { | ||
throw new Error('error_from_async_hook'); | ||
}; |
16 changes: 16 additions & 0 deletions
16
packages/artillery/test/scripts/scenario-async-esm-hooks/test.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
config: | ||
target: "http://asciiart.artillery.io:8080" | ||
phases: | ||
- duration: 10 | ||
arrivalRate: 1 | ||
name: "Phase 1" | ||
processor: "./helpers.mjs" | ||
variables: | ||
isESM: true | ||
|
||
scenarios: | ||
- flow: | ||
- function: emitCustomMetric | ||
- get: | ||
url: "/" | ||
- function: hookThatThrows |
7 changes: 2 additions & 5 deletions
7
packages/artillery/test/scripts/scenarios-typescript/processor.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
import _ from 'lodash'; | ||
|
||
export const myTest = async (context, ee, next) => { | ||
export const myTest = async (context, ee) => { | ||
const isTypescript = _.get(context, 'vars.isTypescript'); | ||
|
||
console.log(`Got context using lodash: ${JSON.stringify(isTypescript)}`); | ||
|
||
ee.emit('counter', 'hey_from_ts', 1); | ||
|
||
next(); | ||
}; | ||
|
||
export const processorWithError = async (context, ee, next) => { | ||
export const processorWithError = async (context, ee) => { | ||
throw new Error('error_from_ts_processor'); | ||
next(); | ||
}; |
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
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
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