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

Function TestContextRequestWithNilConnection

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

Source from the content-addressed store, hash-verified

24)
25
26func TestContextRequestWithNilConnection(t *testing.T) {
27 var nc *nats.Conn
28
29 ctx, cancelCB := context.WithTimeout(context.Background(), 100*time.Millisecond)
30 defer cancelCB() // should always be called, not discarded, to prevent context leak
31
32 _, err := nc.RequestWithContext(ctx, "fast", []byte(""))
33 if err == nil {
34 t.Fatal("Expected request with context and nil connection to fail")
35 }
36 if err != nats.ErrInvalidConnection {
37 t.Fatalf("Expected nats.ErrInvalidConnection, got %v\n", err)
38 }
39}
40
41func testContextRequestWithTimeout(t *testing.T, nc *nats.Conn) {
42 nc.Subscribe("slow", func(m *nats.Msg) {

Callers

nothing calls this directly

Calls 2

RequestWithContextMethod · 0.95
FatalfMethod · 0.80

Tested by

no test coverage detected