(t *testing.T)
| 48 | } |
| 49 | |
| 50 | func TestCloseRunningCommand(t *testing.T) { |
| 51 | ctx := context.TODO() |
| 52 | done := make(chan struct{}) |
| 53 | defer close(done) |
| 54 | |
| 55 | go func() { |
| 56 | c, err := New(ctx, "sh", "-c", "while true; do sleep 1; done") |
| 57 | assert.NilError(t, err) |
| 58 | cmdConn := c.(*commandConn) |
| 59 | assert.Check(t, processAlive(cmdConn.cmd.Process.Pid)) |
| 60 | |
| 61 | n, err := c.Write([]byte("hello")) |
| 62 | assert.Check(t, is.Equal(len("hello"), n)) |
| 63 | assert.NilError(t, err) |
| 64 | assert.Check(t, processAlive(cmdConn.cmd.Process.Pid)) |
| 65 | |
| 66 | err = cmdConn.Close() |
| 67 | assert.NilError(t, err) |
| 68 | assert.Check(t, !processAlive(cmdConn.cmd.Process.Pid)) |
| 69 | done <- struct{}{} |
| 70 | }() |
| 71 | |
| 72 | select { |
| 73 | case <-time.After(5 * time.Second): |
| 74 | t.Error("test did not finish in time") |
| 75 | case <-done: |
| 76 | break |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | func TestCloseTwice(t *testing.T) { |
| 81 | ctx := context.TODO() |
nothing calls this directly
no test coverage detected
searching dependent graphs…