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

Function TestErrOnConnectAndDeadlock

test/conn_test.go:593–639  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

591}
592
593func TestErrOnConnectAndDeadlock(t *testing.T) {
594 // We will hand run a fake server that will timeout and not return a proper
595 // INFO proto. This is to test that we do not deadlock. Issue #18
596
597 l, e := net.Listen("tcp", ":0")
598 if e != nil {
599 t.Fatal("Could not listen on an ephemeral port")
600 }
601 tl := l.(*net.TCPListener)
602 defer tl.Close()
603
604 addr := tl.Addr().(*net.TCPAddr)
605
606 errCh := make(chan error, 1)
607 go func() {
608 conn, err := l.Accept()
609 if err != nil {
610 errCh <- fmt.Errorf("error accepting client connection: %v", err)
611 return
612 }
613 errCh <- nil
614 defer conn.Close()
615 // Send back a mal-formed INFO.
616 conn.Write([]byte("INFOZ \r\n"))
617 }()
618
619 go func() {
620 natsURL := fmt.Sprintf("nats://127.0.0.1:%d/", addr.Port)
621 nc, err := nats.Connect(natsURL)
622 if err == nil {
623 nc.Close()
624 errCh <- errors.New("expected bad INFO err, got none")
625 return
626 }
627 errCh <- nil
628 }()
629
630 // Setup a timer to watch for deadlock
631 select {
632 case e := <-errCh:
633 if e != nil {
634 t.Fatal(e.Error())
635 }
636 case <-time.After(time.Second):
637 t.Fatalf("Connect took too long, deadlock?")
638 }
639}
640
641func TestMoreErrOnConnect(t *testing.T) {
642 l, e := net.Listen("tcp", "127.0.0.1:0")

Callers

nothing calls this directly

Calls 6

ErrorfMethod · 0.80
ConnectMethod · 0.80
FatalfMethod · 0.80
ErrorMethod · 0.65
CloseMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected