# Spike test with a ramping arrival rate: calm baseline, sudden 10x spike,
# recovery. The abort threshold kills the run if errors explode.
name: spike-test
description: baseline -> 10x spike -> recovery

defaults:
  http:
    base_url: https://api.example.com

scenarios:
  spike:
    executor: ramping-arrival-rate
    start_rate: 20
    time_unit: 1s
    pre_allocated_vus: 100
    max_vus: 500
    stages:
      - { duration: 2m, target: 20 }    # baseline
      - { duration: 10s, target: 200 }  # spike!
      - { duration: 1m, target: 200 }   # sustained spike
      - { duration: 10s, target: 20 }   # recover
      - { duration: 2m, target: 20 }    # verify recovery
    flow:
      - request:
          name: checkout
          method: POST
          url: /checkout
          body:
            json: { sku: "A-1", qty: 1 }
          checks:
            - { type: status, one_of: [200, 201] }

thresholds:
  http_req_failed:
    - { threshold: "rate<0.05", abort_on_fail: true, delay_abort_eval: 30s }
  http_req_duration: [ "p(95)<2000" ]
