Skip to content

Commit 34f7899

Browse files
authored
Merge pull request #14 from ActiveState/DX-2901
Ensure time is provided AFTER process state has been asserted
2 parents 3b5b4ea + ac3b175 commit 34f7899

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

termtest_windows.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,21 @@ func (tt *TermTest) waitIndefinitely() error {
2727

2828
tt.opts.Logger.Printf("Waiting for PID %d to exit\n", tt.Cmd().Process.Pid)
2929
for {
30-
// There is a race condition here; which is that the pty could still be processing the last of the output
31-
// when the process exits. This sleep tries to work around this, but on slow hosts this may not be sufficient.
32-
// This also gives some time in between process lookups
33-
time.Sleep(100 * time.Millisecond)
34-
3530
// For some reason os.Process will always return a process even when the process has exited.
3631
// According to the docs this shouldn't happen, but here we are.
3732
// Using gopsutil seems to correctly identify the (not) running process.
3833
exists, err := gopsutil.PidExists(int32(tt.Cmd().Process.Pid))
3934
if err != nil {
4035
return fmt.Errorf("could not find process: %d: %w", tt.Cmd().Process.Pid, err)
4136
}
37+
38+
// There is a race condition here; which is that the pty could still be processing the last of the output
39+
// when the process exits. This sleep tries to work around this, but on slow hosts this may not be sufficient.
40+
// We want this after the process state is asserted, but before we break out, to ensure we give at least the
41+
// specified time AFTER the process has exited.
42+
// This also povides time between process lookups.
43+
time.Sleep(100 * time.Millisecond)
44+
4245
if !exists {
4346
break
4447
}

0 commit comments

Comments
 (0)