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

Function TestCloseWhileWriting

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

Source from the content-addressed store, hash-verified

149}
150
151func TestCloseWhileWriting(t *testing.T) {
152 ctx := context.TODO()
153 c, err := New(ctx, "sh", "-c", "while true; do sleep 1; done")
154 assert.NilError(t, err)
155 cmdConn := c.(*commandConn)
156 assert.Check(t, processAlive(cmdConn.cmd.Process.Pid))
157
158 writeErrC := make(chan error)
159 go func() {
160 for {
161 n, err := c.Write([]byte("hello"))
162 if err != nil {
163 writeErrC <- err
164 return
165 }
166 assert.Equal(t, n, len("hello"))
167 }
168 }()
169
170 err = c.Close()
171 assert.NilError(t, err)
172 assert.Check(t, !processAlive(cmdConn.cmd.Process.Pid))
173
174 writeErr := <-writeErrC
175 assert.ErrorContains(t, writeErr, "file already closed")
176 assert.Check(t, is.ErrorIs(writeErr, fs.ErrClosed))
177}
178
179func TestCloseWhileReading(t *testing.T) {
180 ctx := context.TODO()

Callers

nothing calls this directly

Calls 4

processAliveFunction · 0.85
NewFunction · 0.70
WriteMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…