MCPcopy
hub / github.com/grpc/grpc-go / TestDialWaitsForServerSettings

Method TestDialWaitsForServerSettings

dial_test.go:84–128  ·  dial_test.go::s.TestDialWaitsForServerSettings
(t *testing.T)

Source from the content-addressed store, hash-verified

82}
83
84func (s) TestDialWaitsForServerSettings(t *testing.T) {
85 lis, err := net.Listen("tcp", "localhost:0")
86 if err != nil {
87 t.Fatalf("Error while listening. Err: %v", err)
88 }
89 defer lis.Close()
90 done := make(chan struct{})
91 sent := make(chan struct{})
92 dialDone := make(chan struct{})
93 go func() { // Launch the server.
94 defer func() {
95 close(done)
96 }()
97 conn, err := lis.Accept()
98 if err != nil {
99 t.Errorf("Error while accepting. Err: %v", err)
100 return
101 }
102 defer conn.Close()
103 // Sleep for a little bit to make sure that Dial on client
104 // side blocks until settings are received.
105 time.Sleep(100 * time.Millisecond)
106 framer := http2.NewFramer(conn, conn)
107 close(sent)
108 if err := framer.WriteSettings(http2.Setting{}); err != nil {
109 t.Errorf("Error while writing settings. Err: %v", err)
110 return
111 }
112 <-dialDone // Close conn only after dial returns.
113 }()
114 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
115 defer cancel()
116 client, err := DialContext(ctx, lis.Addr().String(), WithTransportCredentials(insecure.NewCredentials()), WithBlock())
117 close(dialDone)
118 if err != nil {
119 t.Fatalf("Error while dialing. Err: %v", err)
120 }
121 defer client.Close()
122 select {
123 case <-sent:
124 default:
125 t.Fatalf("Dial returned before server settings were sent")
126 }
127 <-done
128}
129
130func (s) TestDialWaitsForServerSettingsAndFails(t *testing.T) {
131 lis, err := net.Listen("tcp", "localhost:0")

Callers

nothing calls this directly

Calls 10

NewCredentialsFunction · 0.92
DialContextFunction · 0.85
WithTransportCredentialsFunction · 0.85
WithBlockFunction · 0.85
FatalfMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.65
AcceptMethod · 0.45
AddrMethod · 0.45

Tested by

no test coverage detected