Download internal/stream/engine_test.go from a3216/ds2api: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/a3216/ds2api/resolve/ce5a019598af8a3a8fa70d3880098df3e850ecd7/internal/stream/engine_test.go
- Command line
-
hf download hf://spaces/a3216/ds2api@ce5a019598af8a3a8fa70d3880098df3e850ecd7/internal/stream/engine_test.go
-
curl -L -o engine_test.go https://huggingface.co/spaces/a3216/ds2api/resolve/ce5a019598af8a3a8fa70d3880098df3e850ecd7/internal/stream/engine_test.go
1.1 kB
| package stream | |
| import ( | |
| "context" | |
| "strings" | |
| "testing" | |
| "ds2api/internal/sse" | |
| ) | |
| func TestConsumeSSEPrefersContextCancellationOverReadyParsedLines(t *testing.T) { | |
| ctx, cancel := context.WithCancel(context.Background()) | |
| cancel() | |
| var finalized bool | |
| var contextDone bool | |
| var parsedCalled bool | |
| ConsumeSSE(ConsumeConfig{ | |
| Context: ctx, | |
| Body: strings.NewReader("data: {\"p\":\"response/content\",\"v\":\"hello\"}\n\ndata: [DONE]\n"), | |
| ThinkingEnabled: false, | |
| InitialType: "text", | |
| KeepAliveInterval: 0, | |
| }, ConsumeHooks{ | |
| OnParsed: func(_ sse.LineResult) ParsedDecision { | |
| parsedCalled = true | |
| return ParsedDecision{} | |
| }, | |
| OnFinalize: func(_ StopReason, _ error) { | |
| finalized = true | |
| }, | |
| OnContextDone: func() { | |
| contextDone = true | |
| }, | |
| }) | |
| if !contextDone { | |
| t.Fatal("expected OnContextDone to run for an already-cancelled context") | |
| } | |
| if finalized { | |
| t.Fatal("expected OnFinalize not to run after context cancellation wins") | |
| } | |
| if parsedCalled { | |
| t.Fatal("expected parsed lines not to be processed after context cancellation wins") | |
| } | |
| } | |