Skip to content

Instantly share code, notes, and snippets.

@hassy
Created March 31, 2016 20:17
Show Gist options
  • Save hassy/f6f7604592f393bbf710ad2e071d6242 to your computer and use it in GitHub Desktop.
Save hassy/f6f7604592f393bbf710ad2e071d6242 to your computer and use it in GitHub Desktop.
Example of using processors in Artillery
config:
target: "http://localhost:8080"
phases:
- duration: 60
arrivalRate: 1
processor: "./processor.js"
scenarios:
- name: "Load the options page"
flow:
- get:
url: "/some/endpoint"
afterResponse: "calculateResponseTimeDelta"
'use strict';
module.exports = {
calculateResponseTimeDelta: calculateResponseTimeDelta
};
function calculateResponseTimeDelta(requestSpec, response, context, ee) {
// requestSpec will be the request spec for this response (currently always null)
// response is a Request.js response object
// context is the scenario context containing scenario variables
// ee is an event emitter for this scenario that we can use to add custom stats to the report
var responseTime = Number(response.headers['x-response-time'].split('ms')[0]);
ee.emit('customStat', { stat: 'response_time', value: responseTime });
}
@sidster-io
Copy link

Hey can you have multiple scripts in processor: ?

@rommik
Copy link

rommik commented May 24, 2017

+1 @Sidrock28. I also would like to know if multiple processors can be used. If no, what is the best way to combine multiple scripts?

@NicolaPrenna
Copy link

@rommik to combine multiple scripts, in the before request you can do a switch on requestParams.url and for each case you have to place a return next().

@rquant
Copy link

rquant commented Nov 26, 2020

Is it possible to use breakpoints in the script?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment