MCPcopy
hub / github.com/nats-io/nats.go / TestContextRequestConnClosed

Function TestContextRequestConnClosed

test/context_test.go:654–674  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

652}
653
654func TestContextRequestConnClosed(t *testing.T) {
655 s := RunDefaultServer()
656 defer s.Shutdown()
657
658 nc := NewDefaultConnection(t)
659 ctx, cancelCB := context.WithCancel(context.Background())
660 defer cancelCB()
661
662 time.AfterFunc(100*time.Millisecond, func() {
663 cancelCB()
664 })
665
666 nc.Close()
667 _, err := nc.RequestWithContext(ctx, "foo", []byte(""))
668 if err == nil {
669 t.Fatal("Expected request to fail with error")
670 }
671 if err != nats.ErrConnectionClosed {
672 t.Errorf("Expected request to fail with connection closed error: %s", err)
673 }
674}
675
676func TestContextBadSubscription(t *testing.T) {
677 s := RunDefaultServer()

Callers

nothing calls this directly

Calls 5

ErrorfMethod · 0.80
RunDefaultServerFunction · 0.70
NewDefaultConnectionFunction · 0.70
CloseMethod · 0.45
RequestWithContextMethod · 0.45

Tested by

no test coverage detected