(t *testing.T)
| 149 | } |
| 150 | |
| 151 | func 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 | |
| 179 | func TestCloseWhileReading(t *testing.T) { |
| 180 | ctx := context.TODO() |
nothing calls this directly
no test coverage detected
searching dependent graphs…