mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-01 08:42:55 +08:00
pkg/shell: Add a short delay in signal handling test.
This commit is contained in:
parent
fed2113a66
commit
b47f8e0dc2
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user