TestProcessStreamPrimingEvent verifies that the streamable client correctly ignores SSE events with empty data buffers, which are used as priming events (e.g. SEP-1699).
(t *testing.T)
| 2567 | // TestProcessStreamPrimingEvent verifies that the streamable client correctly ignores |
| 2568 | // SSE events with empty data buffers, which are used as priming events (e.g. SEP-1699). |
| 2569 | func TestProcessStreamPrimingEvent(t *testing.T) { |
| 2570 | // We create a mock response with a priming event (empty data, with an ID), |
| 2571 | // followed by a normal event. |
| 2572 | sseData := `id: 123 |
| 2573 | |
| 2574 | id: 124 |
| 2575 | data: {"jsonrpc":"2.0","id":1,"result":{}} |
| 2576 | |
| 2577 | ` |
| 2578 | |
| 2579 | ctx := t.Context() |
| 2580 | resp := &http.Response{ |
| 2581 | StatusCode: http.StatusOK, |
| 2582 | Header: http.Header{"Content-Type": []string{"text/event-stream"}}, |
| 2583 | Body: io.NopCloser(strings.NewReader(sseData)), |
| 2584 | } |
| 2585 | |
| 2586 | incoming := make(chan jsonrpc.Message, 10) |
| 2587 | done := make(chan struct{}) |
| 2588 | |
| 2589 | conn := &streamableClientConn{ |
| 2590 | ctx: ctx, |
| 2591 | done: done, |
| 2592 | incoming: incoming, |
| 2593 | failed: make(chan struct{}), |
| 2594 | logger: ensureLogger(nil), |
| 2595 | } |
| 2596 | |
| 2597 | lastID, _, clientClosed := conn.processStream(ctx, "test", resp, nil) |
| 2598 | |
| 2599 | if clientClosed { |
| 2600 | t.Fatalf("processStream was unexpectedly closed by client") |
| 2601 | } |
| 2602 | |
| 2603 | if lastID != "124" { |
| 2604 | t.Errorf("lastEventID = %q, want %q", lastID, "124") |
| 2605 | } |
| 2606 | |
| 2607 | select { |
| 2608 | case msg := <-incoming: |
| 2609 | if res, ok := msg.(*jsonrpc.Response); !(ok && res.ID == jsonrpc2.Int64ID(1)) { |
| 2610 | t.Errorf("got unexpected message: %v", msg) |
| 2611 | } |
| 2612 | default: |
| 2613 | t.Errorf("expected a JSON-RPC message to be produced") |
| 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | // TestScanEventsPingFiltering is a unit test for the low-level event scanning |
| 2618 | // with ping events to verify scanEvents properly parses all event types. |
nothing calls this directly
no test coverage detected
searching dependent graphs…