# Server-Sent Events load: open an event stream, read until a condition, assert on the last event.
name: server-sent-events
description: SSE stream connect/read with checks and assertions

scenarios:
  order_stream:
    executor: constant-vus
    vus: 25
    duration: 2m
    flow:
      - request:
          name: order updates
          url: sse://events.example.com/orders/stream
          headers:
            Authorization: Bearer ${token}
            Last-Event-ID: "${iteration}"
          # Stop the stream after 10 events, on an `event: done`, or after 30s —
          # whichever happens first (all also capped by the request timeout).
          sse:
            events: 10
            until: done
            duration: 30s
          checks:
            - { type: body_contains, name: got update, value: '"status"' }
          assert:
            - { type: status, equals: 200 }
            - { type: js, expression: 'response.body.length > 0' }
      - think_time: { type: constant, duration: 1s }

  metrics_feed:
    executor: constant-arrival-rate
    rate: 50
    duration: 2m
    pre_allocated_vus: 20
    flow:
      - request:
          name: metrics feed
          url: sses://metrics.example.com/live
          headers:
            Accept-Language: en

thresholds:
  http_req_failed: [ "rate<0.01" ]
  data_received: [ "count>0" ]
