Slide 7 of 9

When thresholds fail

Failure signals in the terminal

passed that line; failed the threshold on that line.

When all thresholds pass:

text
✓ http_req_duration..............: avg=186ms  p(95)=312ms
✓ http_req_failed................: 0.00%
✓ checks.........................: 100.00%

When a threshold fails:

text
✗ http_req_duration..............: avg=743ms  p(95)=1247ms
                                   ✗ { p(95)<500 }
✓ http_req_failed................: 0.42%
✓ checks.........................: 99.80%

Exit codes and early stop

Exit codeMeaningCI/CD behavior
0All thresholds passedPipeline continues
99One or more thresholds breachedPipeline fails the step

Add abortOnFail to end the run immediately on a critical breach:

JavaScript
thresholds: {
  http_req_duration: [
    { threshold: 'p(95)<500', abortOnFail: true },
  ],
}

Example: regression caught in CI

A change ships with passing unit tests; the baseline gate runs last. p(95)=683ms vs p(95)<500exit 99, deploy blocked.

text
running (2m01.3s), 00/20 VUs, 1847 complete iterations
     ✓ status is 200
     ✓ body is not empty

     ✗ http_req_duration..............: avg=512ms  p(95)=683ms
                                        ✗ { p(95)<500 }
     ✓ http_req_failed................: 0.00%
     ✓ checks.........................: 100.00%

ERRO threshold breached: http_req_duration p(95)<500, got 683.21ms
MetricLast passingThis run
p95318 ms683 ms
Throughput15.3 requests per second (RPS)15.1 RPS (similar)
Errors0%0%

Latency jumps while throughput is flat usually means per-request work got heavier (for example synchronous database work). Fix the hot path, re-run, pipeline goes green.

Script

Before you build your baseline, it helps to know what failure looks like. When a threshold is breached, k6 changes its behavior in two important ways.

First, the terminal output marks the failed threshold with a red cross instead of a green checkmark. You’ll see the actual value next to the threshold so you can tell exactly how far off it was.

Second, k6 exits with a non-zero exit code. This is what makes thresholds work in continuous integration and deployment pipelines. A non-zero exit code tells the pipeline that the step failed, which can block a deploy or trigger an alert.

If you set abort on fail to true for a threshold, k6 will stop the test immediately when that threshold is breached instead of waiting until the end. This is useful for severe failures where continuing the test would waste time.