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

Function TestClosedConnections

test/conn_test.go:546–591  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

544}
545
546func TestClosedConnections(t *testing.T) {
547 s := RunDefaultServer()
548 defer s.Shutdown()
549
550 nc := NewDefaultConnection(t)
551 defer nc.Close()
552
553 sub, _ := nc.SubscribeSync("foo")
554 if sub == nil {
555 t.Fatal("Failed to create valid subscription")
556 }
557
558 // Test all API endpoints do the right thing with a closed connection.
559 nc.Close()
560 if err := nc.Publish("foo", nil); err != nats.ErrConnectionClosed {
561 t.Fatalf("Publish on closed conn did not fail properly: %v\n", err)
562 }
563 if err := nc.PublishMsg(&nats.Msg{Subject: "foo"}); err != nats.ErrConnectionClosed {
564 t.Fatalf("PublishMsg on closed conn did not fail properly: %v\n", err)
565 }
566 if err := nc.Flush(); err != nats.ErrConnectionClosed {
567 t.Fatalf("Flush on closed conn did not fail properly: %v\n", err)
568 }
569 _, err := nc.Subscribe("foo", nil)
570 if err != nats.ErrConnectionClosed {
571 t.Fatalf("Subscribe on closed conn did not fail properly: %v\n", err)
572 }
573 _, err = nc.SubscribeSync("foo")
574 if err != nats.ErrConnectionClosed {
575 t.Fatalf("SubscribeSync on closed conn did not fail properly: %v\n", err)
576 }
577 _, err = nc.QueueSubscribe("foo", "bar", nil)
578 if err != nats.ErrConnectionClosed {
579 t.Fatalf("QueueSubscribe on closed conn did not fail properly: %v\n", err)
580 }
581 _, err = nc.Request("foo", []byte("help"), 10*time.Millisecond)
582 if err != nats.ErrConnectionClosed {
583 t.Fatalf("Request on closed conn did not fail properly: %v\n", err)
584 }
585 if _, err = sub.NextMsg(10); err != nats.ErrConnectionClosed {
586 t.Fatalf("NextMessage on closed conn did not fail properly: %v\n", err)
587 }
588 if err = sub.Unsubscribe(); err != nats.ErrConnectionClosed {
589 t.Fatalf("Unsubscribe on closed conn did not fail properly: %v\n", err)
590 }
591}
592
593func TestErrOnConnectAndDeadlock(t *testing.T) {
594 // We will hand run a fake server that will timeout and not return a proper

Callers

nothing calls this directly

Calls 13

FatalfMethod · 0.80
NextMsgMethod · 0.80
UnsubscribeMethod · 0.80
RunDefaultServerFunction · 0.70
NewDefaultConnectionFunction · 0.70
SubscribeSyncMethod · 0.65
PublishMethod · 0.65
PublishMsgMethod · 0.65
SubscribeMethod · 0.65
QueueSubscribeMethod · 0.65
CloseMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected