pkg/shell: Add a short delay in signal handling test.

This commit is contained in:
Qi Xiao 2022-06-23 22:03:12 +01:00
parent fed2113a66
commit b47f8e0dc2

View File

@ -3,9 +3,11 @@
package shell
import (
"fmt"
"strings"
"syscall"
"testing"
"time"
"src.elv.sh/pkg/must"
. "src.elv.sh/pkg/prog/progtest"
@ -14,17 +16,22 @@ import (
func TestSignal_USR1(t *testing.T) {
Test(t, &Program{},
ThatElvish("-c", "kill -USR1 $pid").WritesStderrContaining("src.elv.sh/pkg/shell"))
ThatElvish("-c", killCmd("USR1")).WritesStderrContaining("src.elv.sh/pkg/shell"))
}
func TestSignal_Ignored(t *testing.T) {
testutil.InTempDir(t)
Test(t, &Program{},
ThatElvish("-log", "logCHLD", "-c", "kill -CHLD $pid").DoesNothing())
ThatElvish("-log", "logCHLD", "-c", killCmd("CHLD")).DoesNothing())
wantLogCHLD := "signal " + syscall.SIGCHLD.String()
if logCHLD := must.ReadFileString("logCHLD"); !strings.Contains(logCHLD, wantLogCHLD) {
t.Errorf("want log when getting SIGCHLD to contain %q; got:\n%s", wantLogCHLD, logCHLD)
}
}
func killCmd(name string) string {
// Add a delay after kill to ensure that the signal is handled.
return fmt.Sprintf("kill -%v $pid; sleep %v", name, testutil.Scaled(10*time.Millisecond))
}