(t *testing.T)
| 128 | } |
| 129 | |
| 130 | func (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 | |
| 175 | func (s) TestWithTimeout(t *testing.T) { |
| 176 | conn, err := Dial("passthrough:///Non-Existent.Server:80", |
nothing calls this directly
no test coverage detected