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

Method TestDialWaitsForServerSettingsAndFails

dial_test.go:130–173  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

128}
129
130func (s) TestDialWaitsForServerSettingsAndFails(t *testing.T) {
131 lis, err := net.Listen("tcp", "localhost:0")
132 if err != nil {
133 t.Fatalf("Error while listening. Err: %v", err)
134 }
135 done := make(chan struct{})
136 numConns := 0
137 go func() { // Launch the server.
138 defer func() {
139 close(done)
140 }()
141 for {
142 conn, err := lis.Accept()
143 if err != nil {
144 break
145 }
146 numConns++
147 defer conn.Close()
148 }
149 }()
150 ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
151 defer cancel()
152 client, err := DialContext(ctx,
153 lis.Addr().String(),
154 WithTransportCredentials(insecure.NewCredentials()),
155 WithReturnConnectionError(),
156 WithConnectParams(ConnectParams{
157 Backoff: backoff.Config{},
158 MinConnectTimeout: 250 * time.Millisecond,
159 }))
160 lis.Close()
161 if err == nil {
162 client.Close()
163 t.Fatalf("Unexpected success (err=nil) while dialing")
164 }
165 expectedMsg := "server preface"
166 if !strings.Contains(err.Error(), context.DeadlineExceeded.Error()) || !strings.Contains(err.Error(), expectedMsg) {
167 t.Fatalf("DialContext(_) = %v; want a message that includes both %q and %q", err, context.DeadlineExceeded.Error(), expectedMsg)
168 }
169 <-done
170 if numConns < 2 {
171 t.Fatalf("dial attempts: %v; want > 1", numConns)
172 }
173}
174
175func (s) TestWithTimeout(t *testing.T) {
176 conn, err := Dial("passthrough:///Non-Existent.Server:80",

Callers

nothing calls this directly

Calls 11

NewCredentialsFunction · 0.92
DialContextFunction · 0.85
WithTransportCredentialsFunction · 0.85
WithConnectParamsFunction · 0.85
FatalfMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.65
AcceptMethod · 0.45
AddrMethod · 0.45

Tested by

no test coverage detected