Home / Market / sse reconnect replay testing

sse reconnect replay testing

Test Server-Sent Events (SSE) reconnect, Last-Event-ID replay, duplicate/gap/order defects, cursor expiry, HTTP 204 termination, and frame edge cases locally.

skill★ 509080 dlgithubCC-BY-4.0 content; MIT code; upstream exceptions applyInstall in CosmosUpstream Source

Documentation & Preview

--- name: sse-reconnect-replay-testing description: "Test Server-Sent Events (SSE) reconnect, Last-Event-ID replay, duplicate/gap/order defects, cursor expiry, HTTP 204 termination, and frame edge cases locally." category: testing risk: safe source: self source_type: self date_added: "2026-12-01" author: Koushik-Katkam tags: [sse, server-sent-events, eventsource, replay, testing, reliability]

---

SSE Reconnect and Replay Testing

Overview

Verify Server-Sent Events (SSE) stream correctness from the client perspective using deterministic loopback fixtures and a real WHATWG EventSource client (eventsource in Node.js or browser window.EventSource). This workflow isolates reconnect transport mechanics (Last-Event-ID, retry:, HTTP 204 No Content, frame parsing) from application-level acknowledgment and deduplication.

Distinction from existing streaming skills:

When to Use

Prerequisites

How It Works

1. Separate transport delivery from application guarantees

2. Test reconnect, replay anomalies, and frame parsing edge cases

Execute the loopback harness in SSE replay harness:

  1. Controlled disconnect & Last-Event-ID header assertion: Drop the TCP socket immediately after sending event id: 2. Verify the reconnect HTTP request carries Last-Event-ID: 2 and cleanly delivers 1, 2, 3, 4.
  2. Broken replay vs. sequence anomalies: Detect duplicate restarts (1, 2, 1, 2, 3, 4 when a server ignores Last-Event-ID), gaps (1, 2, 4), and out-of-order delivery (1, 2, 4, 3).
  3. Expired replay cursor & explicit resync policy: Requesting Last-Event-ID: 1 when the server buffer retains only >= 3 must follow the service's declared contract — either emitting an explicit event: resync frame before streaming 3, 4 (or terminating cleanly per policy) rather than silently hiding lost events. Verify unified chronological order on one timeline (ordinary messages + custom events interleaved by arrival): Event 1 → Resync notification → Event 3 → Event 4; a swapped order (Event 3 before the resync notification) must fail ordering assertions (negative ordering regression).
  4. Empty id: reset, multiline data:, incomplete trailing frame: Verify id: with empty value resets lastEventId to "" and omits Last-Event-ID on reconnect per WHATWG HTML §9.2.6; multiline data: lines join with \n; incomplete trailing data: frames before disconnect never dispatch to onmessage and never overwrite lastEventId.
  5. HTTP 204 No Content & bounded cleanup: Returning HTTP 204 must transition EventSource.readyState to CLOSED with zero subsequent reconnect attempts. Capture the natural terminal state before manual cleanup and observe a bounded reconnect interval (longer than retry:) *without* manually closing the client first, asserting no additional requests arrive; only then perform manual cleanup. Enforce per-test timeouts, request counters (maxAttempts), es.close(), socket.destroy(), and server.closeAllConnections() so tests never leak sockets or timers.

3. Verify and report client runtime boundaries

Verify exact received (id, event, data) sequences and request headers. Disclose explicitly whenever verification used Node's eventsource package (eventsource@5.1.6) rather than native browser window.EventSource.

Examples

Run the self-contained loopback suite from SSE replay harness:

User request: "Test whether our SSE endpoint safely resumes after disconnect without duplicating or losing events."
Inputs: Synthetic 127.0.0.1 loopback HTTP server + eventsource@5.1.6 client.
Expected result: Correct replay asserts headers ['Last-Event-ID' == '2'] on reconnect and delivers [1, 2, 3, 4];
  broken replay yields [1, 2, 1, 2, 3, 4] and flags duplicates; gap [1, 2, 4] and inversion [1, 2, 4, 3] fail
  monotonicity checks; expired cursor triggers explicit 'resync' event before [3, 4]; empty 'id:' omits
  Last-Event-ID; incomplete trailing frames do not dispatch; and HTTP 204 stops reconnection cleanly.

Limitations

Safety and Side Effects

Sources and related skills