Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility of Adding k6 Checks #2

Open
lbeckman314 opened this issue Aug 8, 2024 · 0 comments
Open

Possibility of Adding k6 Checks #2

lbeckman314 opened this issue Aug 8, 2024 · 0 comments

Comments

@lbeckman314
Copy link
Member

lbeckman314 commented Aug 8, 2024

Overview

Currently the load testing scripts sends requests even if thet return error responses (e.g. sending incorrect credentials returns 401 for subsequent requests).

Checks may be a good option for ensuring successful codes are returned for each request. This could also allow the script to exit early or alert the user if it encounters an error code.

Example Run with Invalid Credentials

credentials.js:

module.exports = {
    EMAIL: 'invalid-user',
    PASSWORD: 'incorrect-password'
}

Running script:

➜ k6 run login.js

# Following errors repeat given bogus password
...
INFO[0009] ~ navigated to the homepage ~                 source=console
ERRO[0009] Failed to load resource: the server responded with a status of 401 ()  browser_source=network line_number=0 source=browser stacktrace="<nil>" url="https://develo
pment.aced-idp.org/user/user"
INFO[0009] ~ navigated login page ~                      source=console
ERRO[0009] Failed to load resource: the server responded with a status of 404 ()  browser_source=network line_number=0 source=browser stacktrace="<nil>" url="https://develo
pment.aced-idp.org/undefined"
ERRO[0009] Failed to load resource: the server responded with a status of 401 ()  browser_source=network line_number=0 source=browser stacktrace="<nil>" url="https://develo
pment.aced-idp.org/user/user"
INFO[0014] ~ login complete ~                            source=console

From the k6 docs

Checks

Checks validate boolean conditions in your test. Testers often use checks to validate that the system is responding with the expected content. For example, a check could validate that a POST request has a response.status == 201, or that the body is of a certain size.

Checks are similar to what many testing frameworks call an assert, but failed checks do not cause the test to abort or finish with a failed status. Instead, k6 keeps track of the rate of failed checks as the test continues to run

Each check creates a rate metric. To make a check abort or fail a test, you can combine it with a Threshold.

Check for HTTP response code

Checks are great for codifying assertions relating to HTTP requests and responses. For example, this snippet makes sure the HTTP response code is a 200:

import { check } from 'k6';
import http from 'k6/http';

export default function () {
  const res = http.get('http://test.k6.io/');
  check(res, {
    'is status 200': (r) => r.status === 200,
  });
}

Additional Resources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant