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

Function TestVariousFailureConditions

test/enc_test.go:537–620  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

535}
536
537func TestVariousFailureConditions(t *testing.T) {
538 ts := RunServerOnPort(ENC_TEST_PORT)
539 defer ts.Shutdown()
540
541 dch := make(chan bool)
542
543 opts := options
544 opts.AsyncErrorCB = func(_ *nats.Conn, _ *nats.Subscription, e error) {
545 dch <- true
546 }
547 nc, _ := opts.Connect()
548 nc.Close()
549
550 if _, err := nats.NewEncodedConn(nil, protobuf.PROTOBUF_ENCODER); err == nil {
551 t.Fatal("Expected an error")
552 }
553
554 if _, err := nats.NewEncodedConn(nc, protobuf.PROTOBUF_ENCODER); err == nil || err != nats.ErrConnectionClosed {
555 t.Fatalf("Wrong error: %v instead of %v", err, nats.ErrConnectionClosed)
556 }
557
558 nc, _ = opts.Connect()
559 defer nc.Close()
560
561 if _, err := nats.NewEncodedConn(nc, "foo"); err == nil {
562 t.Fatal("Expected an error")
563 }
564
565 c, err := nats.NewEncodedConn(nc, protobuf.PROTOBUF_ENCODER)
566 if err != nil {
567 t.Fatalf("Unable to create encoded connection: %v", err)
568 }
569 defer c.Close()
570
571 if _, err := c.Subscribe("bar", func(subj, obj string) {}); err != nil {
572 t.Fatalf("Unable to create subscription: %v", err)
573 }
574
575 if err := c.Publish("bar", &testdata.Person{Name: "Ivan"}); err != nil {
576 t.Fatalf("Unable to publish: %v", err)
577 }
578
579 if err := Wait(dch); err != nil {
580 t.Fatal("Did not get the async error callback")
581 }
582
583 if err := c.PublishRequest("foo", "bar", "foo"); err == nil {
584 t.Fatal("Expected an error")
585 }
586
587 if err := c.Request("foo", "foo", nil, 2*time.Second); err == nil {
588 t.Fatal("Expected an error")
589 }
590
591 nc.Close()
592
593 if err := c.PublishRequest("foo", "bar", &testdata.Person{Name: "Ivan"}); err == nil {
594 t.Fatal("Expected an error")

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
SubscribeMethod · 0.95
PublishMethod · 0.95
PublishRequestMethod · 0.95
RequestMethod · 0.95
ConnectMethod · 0.80
FatalfMethod · 0.80
RunServerOnPortFunction · 0.70
WaitFunction · 0.70
CloseMethod · 0.45

Tested by

no test coverage detected