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

Function TestContextBadSubscription

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

Source from the content-addressed store, hash-verified

674}
675
676func TestContextBadSubscription(t *testing.T) {
677 s := RunDefaultServer()
678 defer s.Shutdown()
679
680 nc := NewDefaultConnection(t)
681 defer nc.Close()
682 ctx, cancelCB := context.WithCancel(context.Background())
683 defer cancelCB()
684 time.AfterFunc(100*time.Millisecond, func() {
685 cancelCB()
686 })
687
688 sub, err := nc.Subscribe("foo", func(_ *nats.Msg) {})
689 if err != nil {
690 t.Fatalf("Expected to be able to subscribe: %s", err)
691 }
692
693 err = sub.Unsubscribe()
694 if err != nil {
695 t.Fatalf("Expected to be able to unsubscribe: %s", err)
696 }
697
698 _, err = sub.NextMsgWithContext(ctx)
699 if err == nil {
700 t.Fatal("Expected to fail getting next message with context")
701 }
702
703 if err != nats.ErrBadSubscription {
704 t.Errorf("Expected request to fail with connection closed error: %s", err)
705 }
706}
707
708func TestFlushWithContext(t *testing.T) {
709 s := RunDefaultServer()

Callers

nothing calls this directly

Calls 8

FatalfMethod · 0.80
UnsubscribeMethod · 0.80
NextMsgWithContextMethod · 0.80
ErrorfMethod · 0.80
RunDefaultServerFunction · 0.70
NewDefaultConnectionFunction · 0.70
SubscribeMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected