mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-25 06:22:24 +02:00
Fix testPresaving/bash by calling SetSid to prevent SIGTTIN signal from killing the test
This commit is contained in:
parent
2c77c3d9c9
commit
33f09ea030
@ -2072,11 +2072,6 @@ echo bar`)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testPresaving(t *testing.T, tester shellTester) {
|
func testPresaving(t *testing.T, tester shellTester) {
|
||||||
if testutils.IsGithubAction() && tester.ShellName() == "bash" {
|
|
||||||
// TODO: Debug the issues with presaving and bash, and re-enable this test
|
|
||||||
t.Skip()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
defer testutils.BackupAndRestore(t)()
|
defer testutils.BackupAndRestore(t)()
|
||||||
userSecret := installHishtory(t, tester, "")
|
userSecret := installHishtory(t, tester, "")
|
||||||
@ -2090,7 +2085,7 @@ func testPresaving(t *testing.T, tester shellTester) {
|
|||||||
// Start a command that will take a long time to execute in the background, so
|
// Start a command that will take a long time to execute in the background, so
|
||||||
// we can check that it was recorded even though it never finished.
|
// we can check that it was recorded even though it never finished.
|
||||||
require.NoError(t, os.Chdir("/"))
|
require.NoError(t, os.Chdir("/"))
|
||||||
go tester.RunInteractiveShell(t, `sleep 13371337`)
|
require.NoError(t, tester.RunInteractiveShellBackground(t, `sleep 13371337`))
|
||||||
time.Sleep(time.Millisecond * 500)
|
time.Sleep(time.Millisecond * 500)
|
||||||
|
|
||||||
// Test that it shows up in hishtory export
|
// Test that it shows up in hishtory export
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/DataDog/datadog-go/statsd"
|
"github.com/DataDog/datadog-go/statsd"
|
||||||
@ -27,6 +28,7 @@ var GLOBAL_STATSD *statsd.Client
|
|||||||
type shellTester interface {
|
type shellTester interface {
|
||||||
RunInteractiveShell(t testing.TB, script string) string
|
RunInteractiveShell(t testing.TB, script string) string
|
||||||
RunInteractiveShellRelaxed(t testing.TB, script string) (string, error)
|
RunInteractiveShellRelaxed(t testing.TB, script string) (string, error)
|
||||||
|
RunInteractiveShellBackground(t testing.TB, script string) error
|
||||||
ShellName() string
|
ShellName() string
|
||||||
}
|
}
|
||||||
type bashTester struct {
|
type bashTester struct {
|
||||||
@ -58,6 +60,16 @@ func (b bashTester) RunInteractiveShellRelaxed(t testing.TB, script string) (str
|
|||||||
return outStr, nil
|
return outStr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b bashTester) RunInteractiveShellBackground(t testing.TB, script string) error {
|
||||||
|
cmd := exec.Command("bash", "-i")
|
||||||
|
// SetSid: true is required to prevent SIGTTIN signal killing the entire test
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
||||||
|
cmd.Stdin = strings.NewReader(script)
|
||||||
|
cmd.Stdout = nil
|
||||||
|
cmd.Stderr = nil
|
||||||
|
return cmd.Start()
|
||||||
|
}
|
||||||
|
|
||||||
func (b bashTester) ShellName() string {
|
func (b bashTester) ShellName() string {
|
||||||
return "bash"
|
return "bash"
|
||||||
}
|
}
|
||||||
@ -88,6 +100,14 @@ func (z zshTester) RunInteractiveShellRelaxed(t testing.TB, script string) (stri
|
|||||||
return outStr, nil
|
return outStr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (z zshTester) RunInteractiveShellBackground(t testing.TB, script string) error {
|
||||||
|
cmd := exec.Command("zsh", "-is")
|
||||||
|
cmd.Stdin = strings.NewReader(script)
|
||||||
|
cmd.Stdout = nil
|
||||||
|
cmd.Stderr = nil
|
||||||
|
return cmd.Start()
|
||||||
|
}
|
||||||
|
|
||||||
func (z zshTester) ShellName() string {
|
func (z zshTester) ShellName() string {
|
||||||
return "zsh"
|
return "zsh"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user