MCPcopy Index your code
hub / github.com/codehamr/codehamr / TestSendEventUnblocksOnCancel

Function TestSendEventUnblocksOnCancel

internal/llm/llm_test.go:423–443  ·  view source on GitHub ↗

TestSendEventUnblocksOnCancel pins sendEvent's anti-wedge invariant: once the parent context is cancelled, a send to an undrained channel must abort via the <-parent.Done() arm instead of blocking the stream goroutine forever. This is the only path exercising that arm. A regression to a plain `out <

(t *testing.T)

Source from the content-addressed store, hash-verified

421// Chat goroutine on Ctrl+C against a full buffer; the goroutine never returns and
422// the deadline below fires.
423func TestSendEventUnblocksOnCancel(t *testing.T) {
424 out := make(chan Event) // unbuffered, no reader → the send blocks until cancel
425 ctx, cancel := context.WithCancel(context.Background())
426
427 done := make(chan bool, 1)
428 go func() {
429 done <- sendEvent(ctx, out, Event{Kind: EventContent, Content: "nobody is reading me"})
430 }()
431
432 // The send is wedged (no reader on out); cancelling must release it.
433 cancel()
434
435 select {
436 case ok := <-done:
437 if ok {
438 t.Fatal("sendEvent returned true for a send nobody drained; it must report false after cancel")
439 }
440 case <-time.After(2 * time.Second):
441 t.Fatal("sendEvent wedged on an undrained channel after cancel - the anti-wedge <-parent.Done() arm is missing")
442 }
443}
444
445// TestChat401: maps to typed ErrUnauthorized.
446func TestChat401(t *testing.T) {

Callers

nothing calls this directly

Calls 1

sendEventFunction · 0.85

Tested by

no test coverage detected