Skip to content

Commit ccf4b43

Browse files
committed
testscript: ignore result when interrupting background processes
When an entire script runs and the end is reached, any background processes begun with a '&' command get interrupted or killed, depending on the platform and timeout, and we wait for them to finish. We also checked their resulting status code and failed if they didn't exit with a status code of 0. However, as explained in the comment, this would always fail on Windows, given that it doesn't have interrupt signals so we would kill directly, causing a "signal: killed" error. Worse, any failures here caused a `panic: fail now!` as that is how we bubble up errors when a script command is being run, but such panics were not being recovered once we reached the end of a script. Now that we don't check the result anymore here, the panics are gone. Fixes #228. Fixes #260.
1 parent 66960b6 commit ccf4b43

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Let testscript stop signalcatcher at the end of the testscript.
2+
3+
signalcatcher &
4+
waitfile catchsignal

testscript/testscript.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,11 @@ func (ts *TestScript) run() {
651651
for _, bg := range ts.background {
652652
interruptProcess(bg.cmd.Process)
653653
}
654-
ts.cmdWait(false, nil)
654+
// On some platforms like Windows, we kill background commands directly
655+
// as we can't send them an interrupt signal, so they always fail.
656+
// Moreover, it's relatively common for a process to fail when interrupted.
657+
// Once we've reached the end of the script, ignore the status of background commands.
658+
ts.waitBackground(false)
655659

656660
// If we reached here but we've failed (probably because ContinueOnError
657661
// was set), don't wipe the log and print "PASS".

0 commit comments

Comments
 (0)