Makes sure we don't hang forever on the initial connection. https://github.com/docker/cli/issues/3652
(t *testing.T)
| 208 | // Makes sure we don't hang forever on the initial connection. |
| 209 | // https://github.com/docker/cli/issues/3652 |
| 210 | func TestInitializeFromClientHangs(t *testing.T) { |
| 211 | tmpDir := t.TempDir() |
| 212 | socket := filepath.Join(tmpDir, "my.sock") |
| 213 | l, err := net.Listen("unix", socket) |
| 214 | assert.NilError(t, err) |
| 215 | |
| 216 | receiveReqCh := make(chan bool) |
| 217 | timeoutCtx, cancel := context.WithTimeout(context.TODO(), time.Second) |
| 218 | defer cancel() |
| 219 | |
| 220 | // Simulate a server that hangs on connections. |
| 221 | ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 222 | select { |
| 223 | case <-timeoutCtx.Done(): |
| 224 | case receiveReqCh <- true: // Blocks until someone receives on the channel. |
| 225 | } |
| 226 | _, _ = w.Write([]byte("OK")) |
| 227 | })) |
| 228 | ts.Listener = l |
| 229 | ts.Start() |
| 230 | defer ts.Close() |
| 231 | |
| 232 | opts := &flags.ClientOptions{Hosts: []string{"unix://" + socket}} |
| 233 | configFile := &configfile.ConfigFile{} |
| 234 | apiClient, err := NewAPIClientFromFlags(opts, configFile) |
| 235 | assert.NilError(t, err) |
| 236 | |
| 237 | initializedCh := make(chan bool) |
| 238 | |
| 239 | go func() { |
| 240 | cli := &DockerCli{client: apiClient, initTimeout: time.Millisecond} |
| 241 | err := cli.Initialize(flags.NewClientOptions()) |
| 242 | assert.Check(t, err) |
| 243 | cli.CurrentVersion() |
| 244 | close(initializedCh) |
| 245 | }() |
| 246 | |
| 247 | select { |
| 248 | case <-timeoutCtx.Done(): |
| 249 | t.Fatal("timeout waiting for initialization to complete") |
| 250 | case <-initializedCh: |
| 251 | } |
| 252 | |
| 253 | select { |
| 254 | case <-timeoutCtx.Done(): |
| 255 | t.Fatal("server never received an init request") |
| 256 | case <-receiveReqCh: |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | func TestNewDockerCliAndOperators(t *testing.T) { |
| 261 | outbuf := bytes.NewBuffer(nil) |
nothing calls this directly
no test coverage detected
searching dependent graphs…