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

Function TestAutoUnsubOnSyncSubCanStillRespond

test/sub_test.go:1582–1613  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1580}
1581
1582func TestAutoUnsubOnSyncSubCanStillRespond(t *testing.T) {
1583 s := RunDefaultServer()
1584 defer s.Shutdown()
1585
1586 nc := NewDefaultConnection(t)
1587 defer nc.Close()
1588
1589 subj := nuid.Next()
1590 sub, err := nc.SubscribeSync(subj)
1591 if err != nil {
1592 t.Fatalf("Error susbscribing: %v", err)
1593 }
1594 // When the single message is delivered, the
1595 // auto unsub will reap the subscription removing
1596 // the connection, make sure Respond still works.
1597 if err := sub.AutoUnsubscribe(1); err != nil {
1598 t.Fatalf("Error autounsub: %v", err)
1599 }
1600
1601 inbox := nats.NewInbox()
1602 if err = nc.PublishRequest(subj, inbox, nil); err != nil {
1603 t.Fatalf("Error making request: %v", err)
1604 }
1605
1606 m, err := sub.NextMsg(time.Second)
1607 if err != nil {
1608 t.Fatalf("Error getting next message")
1609 }
1610 if err := m.Respond(nil); err != nil {
1611 t.Fatalf("Error responding: %v", err)
1612 }
1613}
1614
1615func TestSubscribe_ClosedHandler(t *testing.T) {
1616 s := RunDefaultServer()

Callers

nothing calls this directly

Calls 11

FatalfMethod · 0.80
AutoUnsubscribeMethod · 0.80
NewInboxMethod · 0.80
NextMsgMethod · 0.80
RunDefaultServerFunction · 0.70
NewDefaultConnectionFunction · 0.70
NextMethod · 0.65
SubscribeSyncMethod · 0.65
RespondMethod · 0.65
CloseMethod · 0.45
PublishRequestMethod · 0.45

Tested by

no test coverage detected