(t *testing.T)
| 110 | } |
| 111 | |
| 112 | func TestEOFTimeout(t *testing.T) { |
| 113 | ctx := context.TODO() |
| 114 | done := make(chan struct{}) |
| 115 | go func() { |
| 116 | c, err := New(ctx, "sh", "-c", "sleep 20") |
| 117 | assert.NilError(t, err) |
| 118 | cmdConn := c.(*commandConn) |
| 119 | assert.Check(t, processAlive(cmdConn.cmd.Process.Pid)) |
| 120 | |
| 121 | cmdConn.stdout = mockStdoutEOF{} |
| 122 | |
| 123 | b := make([]byte, 32) |
| 124 | n, err := c.Read(b) |
| 125 | assert.Check(t, is.Equal(0, n)) |
| 126 | assert.ErrorContains(t, err, "did not exit after EOF") |
| 127 | |
| 128 | done <- struct{}{} |
| 129 | }() |
| 130 | |
| 131 | // after receiving an EOF, we try to kill the command |
| 132 | // if it doesn't exit after 10s, we throw an error |
| 133 | select { |
| 134 | case <-time.After(12 * time.Second): |
| 135 | t.Error("test did not finish in time") |
| 136 | case <-done: |
| 137 | break |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | type mockStdoutEOF struct{} |
| 142 |
nothing calls this directly
no test coverage detected
searching dependent graphs…