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

Function TestPublishErrorAfterSubscribeDecodeError

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

Source from the content-addressed store, hash-verified

485}
486
487func TestPublishErrorAfterSubscribeDecodeError(t *testing.T) {
488 ts := RunServerOnPort(ENC_TEST_PORT)
489 defer ts.Shutdown()
490 opts := options
491 nc, _ := opts.Connect()
492 defer nc.Close()
493
494 // Override default handler for test.
495 nc.SetErrorHandler(func(_ *nats.Conn, _ *nats.Subscription, _ error) {})
496
497 c, _ := nats.NewEncodedConn(nc, nats.JSON_ENCODER)
498
499 //Test message type
500 type Message struct {
501 Message string
502 }
503 const testSubj = "test"
504
505 c.Subscribe(testSubj, func(msg *Message) {})
506
507 // Publish invalid json to catch decode error in subscription callback
508 c.Publish(testSubj, `foo`)
509 c.Flush()
510
511 // Next publish should be successful
512 if err := c.Publish(testSubj, Message{"2"}); err != nil {
513 t.Error("Fail to send correct json message after decode error in subscription")
514 }
515}
516
517func TestPublishErrorAfterInvalidPublishMessage(t *testing.T) {
518 ts := RunServerOnPort(ENC_TEST_PORT)

Callers

nothing calls this directly

Calls 8

SubscribeMethod · 0.95
PublishMethod · 0.95
FlushMethod · 0.95
ConnectMethod · 0.80
SetErrorHandlerMethod · 0.80
RunServerOnPortFunction · 0.70
ErrorMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected