mirror of
https://github.com/python/cpython.git
synced 2025-12-22 16:39:14 +00:00
gh-137179: Fix flaky test_history_survive_crash test (gh-137180)
Some checks are pending
Tests / Docs (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Ubuntu SSL tests with AWS-LC (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Some checks are pending
Tests / Docs (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Ubuntu SSL tests with AWS-LC (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Kill the REPL subprocess once it prints the output from the command immediately before the `time.sleep()`.
This commit is contained in:
parent
0b4e13c265
commit
98d462cf4d
1 changed files with 19 additions and 5 deletions
|
|
@ -51,6 +51,7 @@ class ReplTestCase(TestCase):
|
|||
cwd: str | None = None,
|
||||
skip: bool = False,
|
||||
timeout: float = SHORT_TIMEOUT,
|
||||
exit_on_output: str | None = None,
|
||||
) -> tuple[str, int]:
|
||||
temp_dir = None
|
||||
if cwd is None:
|
||||
|
|
@ -64,6 +65,7 @@ class ReplTestCase(TestCase):
|
|||
cwd=cwd,
|
||||
skip=skip,
|
||||
timeout=timeout,
|
||||
exit_on_output=exit_on_output,
|
||||
)
|
||||
finally:
|
||||
if temp_dir is not None:
|
||||
|
|
@ -78,6 +80,7 @@ class ReplTestCase(TestCase):
|
|||
cwd: str,
|
||||
skip: bool,
|
||||
timeout: float,
|
||||
exit_on_output: str | None,
|
||||
) -> tuple[str, int]:
|
||||
assert pty
|
||||
master_fd, slave_fd = pty.openpty()
|
||||
|
|
@ -123,6 +126,11 @@ class ReplTestCase(TestCase):
|
|||
except OSError:
|
||||
break
|
||||
output.append(data)
|
||||
if exit_on_output is not None:
|
||||
output = ["".join(output)]
|
||||
if exit_on_output in output[0]:
|
||||
process.kill()
|
||||
break
|
||||
else:
|
||||
os.close(master_fd)
|
||||
process.kill()
|
||||
|
|
@ -1718,18 +1726,24 @@ class TestMain(ReplTestCase):
|
|||
|
||||
commands = "1\n2\n3\nexit()\n"
|
||||
output, exit_code = self.run_repl(commands, env=env, skip=True)
|
||||
self.assertEqual(exit_code, 0)
|
||||
|
||||
commands = "spam\nimport time\ntime.sleep(1000)\nquit\n"
|
||||
try:
|
||||
self.run_repl(commands, env=env, timeout=3)
|
||||
except AssertionError:
|
||||
pass
|
||||
# Run until "0xcafe" is printed (as "51966") and then kill the
|
||||
# process to simulate a crash. Note that the output also includes
|
||||
# the echoed input commands.
|
||||
commands = "spam\nimport time\n0xcafe\ntime.sleep(1000)\nquit\n"
|
||||
output, exit_code = self.run_repl(commands, env=env,
|
||||
exit_on_output="51966")
|
||||
self.assertNotEqual(exit_code, 0)
|
||||
|
||||
history = pathlib.Path(hfile.name).read_text()
|
||||
self.assertIn("2", history)
|
||||
self.assertIn("exit()", history)
|
||||
self.assertIn("spam", history)
|
||||
self.assertIn("import time", history)
|
||||
# History is written after each command's output is printed to the
|
||||
# console, so depending on how quickly the process is killed,
|
||||
# the last command may or may not be written to the history file.
|
||||
self.assertNotIn("sleep", history)
|
||||
self.assertNotIn("quit", history)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue