MCPcopy Create free account
hub / github.com/docker/cli / TestCloseWhileReading

Function TestCloseWhileReading

cli/connhelper/commandconn/commandconn_unix_test.go:179–205  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

177}
178
179func TestCloseWhileReading(t *testing.T) {
180 ctx := context.TODO()
181 c, err := New(ctx, "sh", "-c", "while true; do sleep 1; done")
182 assert.NilError(t, err)
183 cmdConn := c.(*commandConn)
184 assert.Check(t, processAlive(cmdConn.cmd.Process.Pid))
185
186 readErrC := make(chan error)
187 go func() {
188 for {
189 b := make([]byte, 32)
190 n, err := c.Read(b)
191 if err != nil {
192 readErrC <- err
193 return
194 }
195 assert.Check(t, is.Equal(0, n))
196 }
197 }()
198
199 err = cmdConn.Close()
200 assert.NilError(t, err)
201 assert.Check(t, !processAlive(cmdConn.cmd.Process.Pid))
202
203 readErr := <-readErrC
204 assert.Check(t, is.ErrorIs(readErr, fs.ErrClosed))
205}
206
207// processAlive returns true if a process with a given pid is running. It only considers
208// positive PIDs; 0 (all processes in the current process group), -1 (all processes

Callers

nothing calls this directly

Calls 4

processAliveFunction · 0.85
NewFunction · 0.70
ReadMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…