(t *testing.T)
| 177 | } |
| 178 | |
| 179 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…