(t *testing.T)
| 485 | } |
| 486 | |
| 487 | func 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 | |
| 517 | func TestPublishErrorAfterInvalidPublishMessage(t *testing.T) { |
| 518 | ts := RunServerOnPort(ENC_TEST_PORT) |
nothing calls this directly
no test coverage detected