---
title: "Validate thresholds work | Grafana Labs"
description: "Re-run your test to confirm thresholds produce the correct pass or fail exit code."
---

# Validate thresholds work

Adding thresholds to your script isn’t enough. You need to confirm they actually pass and fail as expected. In this milestone, you run the test twice: once to verify it passes under normal conditions, and once with a deliberately strict threshold to confirm it fails correctly.

To validate your thresholds, complete the following steps:

1. Run the test:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   k6 run baseline.js
   ```
2. At the top of the summary output, look for the **THRESHOLDS** section and verify that all thresholds pass:
   
   text ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```text
   THRESHOLDS
     checks
       ✓ 'rate>0.99' rate=100.00%
   
     http_req_duration
       ✓ 'p(95)<500' p(95)=54.42ms
   
     http_req_failed
       ✓ 'rate<0.01' rate=0.00%
   ```
   
   A ✓ next to each threshold means it passed. The `rate>0.99` on the checks threshold means the check pass rate must be above 99%. This is not related to p99 latency. The exit code should be `0`, which signals success.
3. Verify the exit code in your terminal:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   echo $?
   ```
   
   The output should be `0`.
4. Now test that a threshold failure works correctly. Temporarily set a very strict latency threshold that your system can’t meet. Open `baseline.js` and change the `http_req_duration` threshold:
   
   JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```javascript
   thresholds: {
     http_req_duration: ['p(95)<1'],
     http_req_failed: ['rate<0.01'],
     checks: ['rate>0.99'],
   },
   ```
   
   A p95 under 1 ms is impossible for any real HTTP request, so this threshold should fail.
5. Run the test again:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   k6 run baseline.js
   ```
   
   The **THRESHOLDS** section now shows a ✗ next to the failed threshold:
   
   text ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```text
   THRESHOLDS
     checks
       ✓ 'rate>0.99' rate=100.00%
   
     http_req_duration
       ✗ 'p(95)<1' p(95)=54.42ms
   
     http_req_failed
       ✓ 'rate<0.01' rate=0.00%
   ```
6. Verify the exit code is non-zero:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   echo $?
   ```
   
   The output should be `99`, which is k6’s exit code for threshold failures. This non-zero exit code is what CI/CD systems use to detect a failed test.
7. Restore your original threshold value before continuing:
   
   JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```javascript
   http_req_duration: ['p(95)<500'],
   ```

You’ve confirmed that your thresholds work in both directions: passing when metrics are within bounds and failing when they’re breached.

In the next milestone, you save your results to k6 Cloud for historical tracking and team visibility.
