$npx -y skills add PramodDutta/qaskills --skill artillery-loadWrite and run Artillery load tests with YAML phases and scenarios, CSV data payloads, the expect plugin for functional checks, and ensure thresholds that fail CI when latency or error budgets are breached.
| 1 | # Artillery Load Testing |
| 2 | |
| 3 | This skill makes an AI agent author Artillery 2.x load tests as declarative YAML: realistic traffic phases, multi-step scenarios with captured variables, CSV-driven virtual user data, functional `expect` checks inside load flows, and `ensure` thresholds that turn latency regressions into red CI builds. Trigger it when a project contains `artillery.yml`, `artillery` in package.json, or when the user asks for load, stress, soak, or spike testing of an HTTP API or website in a Node.js stack. |
| 4 | |
| 5 | ## Core Principles |
| 6 | |
| 7 | 1. **Model traffic in phases, never one flat rate.** Real load has a warm-up, a ramp, and a sustained plateau. A single `arrivalRate` hides cold-start effects and autoscaling lag. Always define at least warm-up, ramp, and sustain phases. |
| 8 | 2. **`arrivalRate` is new virtual users per second, not concurrency.** Each arriving VU runs the whole scenario. If your scenario takes 10 seconds and you arrive 50/sec, you have roughly 500 concurrent users. Calculate this before picking numbers. |
| 9 | 3. **Thresholds belong in the test file, not in a wiki.** Use the `ensure` plugin so `artillery run` exits non-zero when p95/p99 or error rate budgets are blown. A load test that cannot fail is a demo, not a test. |
| 10 | 4. **Assert correctness under load with `expect`.** A server returning 200 with an empty body at p99 latency is still broken. Check `statusCode`, `contentType`, and `hasProperty` inside the flow. |
| 11 | 5. **Parameterize virtual users from CSV payloads.** Hammering one account exercises one cache line and one DB row. Use `payload` with hundreds of distinct credentials and SKUs to defeat caches realistically. |
| 12 | 6. **Never load test production without a plan; never load test third parties at all.** Point Artillery at a staging environment sized like production, announce test windows, and rate-limit anything that crosses a vendor boundary. |
| 13 | |
| 14 | ## Setup |
| 15 | |
| 16 | ```bash |
| 17 | npm install --save-dev artillery@latest |
| 18 | npx artillery version |
| 19 | |
| 20 | # Run a test locally |
| 21 | npx artillery run load/checkout.yml |
| 22 | |
| 23 | # Save raw metrics for trend analysis |
| 24 | npx artillery run load/checkout.yml --output artillery-report.json |
| 25 | ``` |
| 26 | |
| 27 | ## Patterns |
| 28 | |
| 29 | ### 1. Phases and a multi-step scenario with capture |
| 30 | |
| 31 | ```yaml |
| 32 | # load/checkout.yml |
| 33 | config: |
| 34 | target: https://staging-api.example.com |
| 35 | http: |
| 36 | timeout: 10 |
| 37 | phases: |
| 38 | - duration: 60 |
| 39 | arrivalRate: 2 |
| 40 | name: warm-up |
| 41 | - duration: 120 |
| 42 | arrivalRate: 5 |
| 43 | rampTo: 40 |
| 44 | name: ramp-to-peak |
| 45 | - duration: 300 |
| 46 | arrivalRate: 40 |
| 47 | name: sustained-peak |
| 48 | payload: |
| 49 | path: users.csv |
| 50 | fields: |
| 51 | |
| 52 | - password |
| 53 | order: random |
| 54 | skipHeader: true |
| 55 | plugins: |
| 56 | expect: {} |
| 57 | ensure: {} |
| 58 | ensure: |
| 59 | thresholds: |
| 60 | - http.response_time.p95: 250 |
| 61 | - http.response_time.p99: 500 |
| 62 | conditions: |
| 63 | - expression: http.codes.200 > 0 |
| 64 | strict: true |
| 65 | maxErrorRate: 1 |
| 66 | |
| 67 | scenarios: |
| 68 | - name: login-browse-order |
| 69 | flow: |
| 70 | - post: |
| 71 | url: /auth/login |
| 72 | json: |
| 73 | email: '{{ email }}' |
| 74 | password: '{{ password }}' |
| 75 | capture: |
| 76 | - json: $.token |
| 77 | as: authToken |
| 78 | expect: |
| 79 | - statusCode: 200 |
| 80 | - contentType: json |
| 81 | - hasProperty: token |
| 82 | - get: |
| 83 | url: /products?category=audio |
| 84 | headers: |
| 85 | Authorization: 'Bearer {{ authToken }}' |
| 86 | capture: |
| 87 | - json: $[0].id |
| 88 | as: productId |
| 89 | expect: |
| 90 | - statusCode: 200 |
| 91 | - post: |
| 92 | url: /orders |
| 93 | headers: |
| 94 | Authorization: 'Bearer {{ authToken }}' |
| 95 | json: |
| 96 | productId: '{{ productId }}' |
| 97 | quantity: 1 |
| 98 | expect: |
| 99 | - statusCode: 201 |
| 100 | - hasProperty: orderId |
| 101 | - think: 2 |
| 102 | ``` |
| 103 | |
| 104 | ### 2. CSV payload file |
| 105 | |
| 106 | ```csv |
| 107 | email,password |
| 108 | loadtest-001@example.com,Str0ngPass!001 |
| 109 | loadtest-002@example.com,Str0ngPass!002 |
| 110 | loadtest-003@example.com,Str0ngPass!003 |
| 111 | loadtest-004@example.com,Str0ngPass!004 |
| 112 | ``` |
| 113 | |
| 114 | Generate hundreds of rows with a one-liner instead of writing them by hand: |
| 115 | |
| 116 | ```bash |
| 117 | seq -w 1 500 | awk -F, 'BEGIN{print "email,password"} {printf "loadtest-%s@example.com,Str0ngPass!%s\n", $1, $1}' > users.csv |
| 118 | ``` |
| 119 | |
| 120 | ### 3. Custom logic with a JavaScript processor |
| 121 | |
| 122 | ```yaml |
| 123 | # In config: |
| 124 | config: |
| 125 | target: https://staging-api.example.com |
| 126 | processor: ./processor.js |
| 127 | |
| 128 | scenarios: |
| 129 | - name: create-or |