fix: test slowness on usage of exit
This commit is contained in:
@@ -26,7 +26,7 @@ func loadRecordedInput(path string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return trimTrailingNewlineAfterEOF(data), nil
|
return trimTrailingReplayNewline(data), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadRecordedOutput(path string) ([]byte, error) {
|
func loadRecordedOutput(path string) ([]byte, error) {
|
||||||
@@ -108,8 +108,13 @@ func findScriptFooter(data []byte) (int, footerMatchState) {
|
|||||||
return candidate, footerFound
|
return candidate, footerFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func trimTrailingNewlineAfterEOF(data []byte) []byte {
|
func trimTrailingReplayNewline(data []byte) []byte {
|
||||||
if len(data) >= 2 && data[len(data)-2] == eofByte && data[len(data)-1] == '\n' {
|
// util-linux script records the final Enter as "\r\n", but replay feeds the
|
||||||
|
// bytes from a file rather than a tty. If the shell exits after consuming the
|
||||||
|
// trailing '\r', the leftover '\n' can trigger script's ~2s non-tty stdin
|
||||||
|
// delay before it shuts down. Keep the '\r' that bash consumed, drop only the
|
||||||
|
// synthetic final '\n'. The same cleanup is needed after a terminal EOF byte.
|
||||||
|
if len(data) >= 2 && data[len(data)-1] == '\n' && (data[len(data)-2] == '\r' || data[len(data)-2] == eofByte) {
|
||||||
return data[:len(data)-1]
|
return data[:len(data)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,21 @@ func TestLoadRecordedInputTrimsTrailingNewlineAfterEOF(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadRecordedInputTrimsTrailingNewlineAfterCarriageReturn(t *testing.T) {
|
||||||
|
path := filepath.Join(t.TempDir(), "in")
|
||||||
|
writeFile(t, path, "echo hi\rexit\r\n")
|
||||||
|
|
||||||
|
got, err := loadRecordedInput(path)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("loadRecordedInput() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
want := "echo hi\rexit\r"
|
||||||
|
if string(got) != want {
|
||||||
|
t.Fatalf("loadRecordedInput() = %q, want %q", string(got), want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoadRecordedInputLeavesNormalTrailingNewline(t *testing.T) {
|
func TestLoadRecordedInputLeavesNormalTrailingNewline(t *testing.T) {
|
||||||
path := filepath.Join(t.TempDir(), "in")
|
path := filepath.Join(t.TempDir(), "in")
|
||||||
writeFile(t, path, "echo hi\n")
|
writeFile(t, path, "echo hi\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user