Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions termtest_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ func (tt *TermTest) waitIndefinitely() error {

tt.opts.Logger.Printf("Waiting for PID %d to exit\n", tt.Cmd().Process.Pid)
for {
// There is a race condition here; which is that the pty could still be processing the last of the output
// when the process exits. This sleep tries to work around this, but on slow hosts this may not be sufficient.
// This also gives some time in between process lookups
time.Sleep(100 * time.Millisecond)

// For some reason os.Process will always return a process even when the process has exited.
// According to the docs this shouldn't happen, but here we are.
// Using gopsutil seems to correctly identify the (not) running process.
exists, err := gopsutil.PidExists(int32(tt.Cmd().Process.Pid))
if err != nil {
return fmt.Errorf("could not find process: %d: %w", tt.Cmd().Process.Pid, err)
}

// There is a race condition here; which is that the pty could still be processing the last of the output
// when the process exits. This sleep tries to work around this, but on slow hosts this may not be sufficient.
// We want this after the process state is asserted, but before we break out, to ensure we give at least the
// specified time AFTER the process has exited.
// This also povides time between process lookups.
time.Sleep(100 * time.Millisecond)

if !exists {
break
}
Expand Down