5

I am working on some test requirement where I have to fail a load test scenario when p95>100ms. I have written below test snippet:

config:
  target: "https://news.google.com"
  # Responses have to be sent within 10 seconds or the request will be aborted
  timeout: 10
  ensure:
      p95: 800
  phases:
    - duration: 10
      arrivalRate: 1

scenarios:
  - name: "Hit news google"
    flow:
    - get:
          url: "/dssw.js_data?_reqid=34556&rt=j"
          expect:
            - statusCode: 300
            - contentType: json

I want this test scenario to be visible in some kind of reports as how many test case has been failed and pass. Artillery generates the report only showing the performance stats but how to show the report as per the test performance assertion failed in some kind of report.

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
QA_hacks
  • 257
  • 1
  • 6
  • 15

2 Answers2

4

One option is to implement a hook in javascript that looks at the status code and if deems the status as failed returns an error trough the next function.

Example js hook function:

function exitOnFail(requestParams, response, context, ee, next) {
  const statusCode = parseInt(response.statusCode);
  if (statusCode > 399) {
    next(new Error(`${requestParams.url} StatusCode: ${statusCode}`));
  } else {
    next();
  }
}

and connecting the hook to the request:

config:
 ...
 processor: './scriptfile.js'

 ...

scenarios:
  - flow:
    - get:
        url: some/url
        ...
        afterResponse: 'exitOnFail'


0

By using the ensure plugin in artillery v2, you will need to add it to your plugins config as well and npm i -D artillery-plugins-ensure. For more information, please see here: https://www.artillery.io/docs/reference/extensions/ensure Ensure returns a non-zero code upon failure. I had to use artillery v2.0.0-30, something is up with the latest version logging the output. Good luck!

config:
  ...
  plugins:
    ensure: { }

config:
  ...
  ensure:
    conditions:
      - expression: "http.codes.200 == http.requests"
        strict: true