(t *testing.T)
| 544 | } |
| 545 | |
| 546 | func TestClosedConnections(t *testing.T) { |
| 547 | s := RunDefaultServer() |
| 548 | defer s.Shutdown() |
| 549 | |
| 550 | nc := NewDefaultConnection(t) |
| 551 | defer nc.Close() |
| 552 | |
| 553 | sub, _ := nc.SubscribeSync("foo") |
| 554 | if sub == nil { |
| 555 | t.Fatal("Failed to create valid subscription") |
| 556 | } |
| 557 | |
| 558 | // Test all API endpoints do the right thing with a closed connection. |
| 559 | nc.Close() |
| 560 | if err := nc.Publish("foo", nil); err != nats.ErrConnectionClosed { |
| 561 | t.Fatalf("Publish on closed conn did not fail properly: %v\n", err) |
| 562 | } |
| 563 | if err := nc.PublishMsg(&nats.Msg{Subject: "foo"}); err != nats.ErrConnectionClosed { |
| 564 | t.Fatalf("PublishMsg on closed conn did not fail properly: %v\n", err) |
| 565 | } |
| 566 | if err := nc.Flush(); err != nats.ErrConnectionClosed { |
| 567 | t.Fatalf("Flush on closed conn did not fail properly: %v\n", err) |
| 568 | } |
| 569 | _, err := nc.Subscribe("foo", nil) |
| 570 | if err != nats.ErrConnectionClosed { |
| 571 | t.Fatalf("Subscribe on closed conn did not fail properly: %v\n", err) |
| 572 | } |
| 573 | _, err = nc.SubscribeSync("foo") |
| 574 | if err != nats.ErrConnectionClosed { |
| 575 | t.Fatalf("SubscribeSync on closed conn did not fail properly: %v\n", err) |
| 576 | } |
| 577 | _, err = nc.QueueSubscribe("foo", "bar", nil) |
| 578 | if err != nats.ErrConnectionClosed { |
| 579 | t.Fatalf("QueueSubscribe on closed conn did not fail properly: %v\n", err) |
| 580 | } |
| 581 | _, err = nc.Request("foo", []byte("help"), 10*time.Millisecond) |
| 582 | if err != nats.ErrConnectionClosed { |
| 583 | t.Fatalf("Request on closed conn did not fail properly: %v\n", err) |
| 584 | } |
| 585 | if _, err = sub.NextMsg(10); err != nats.ErrConnectionClosed { |
| 586 | t.Fatalf("NextMessage on closed conn did not fail properly: %v\n", err) |
| 587 | } |
| 588 | if err = sub.Unsubscribe(); err != nats.ErrConnectionClosed { |
| 589 | t.Fatalf("Unsubscribe on closed conn did not fail properly: %v\n", err) |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | func TestErrOnConnectAndDeadlock(t *testing.T) { |
| 594 | // We will hand run a fake server that will timeout and not return a proper |
nothing calls this directly
no test coverage detected