2020-06-08 15:31:18 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from pexpect_helper import SpawnedProc
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2020-06-08 16:49:03 +00:00
|
|
|
import time
|
2020-06-08 15:31:18 +00:00
|
|
|
|
|
|
|
sp = SpawnedProc()
|
2020-06-08 15:32:56 +00:00
|
|
|
send, sendline, sleep, expect_prompt, expect_re = (
|
|
|
|
sp.send,
|
|
|
|
sp.sendline,
|
|
|
|
sp.sleep,
|
|
|
|
sp.expect_prompt,
|
|
|
|
sp.expect_re,
|
|
|
|
)
|
2020-06-08 15:31:18 +00:00
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# Verify that if we attempt to exit with a job in the background we get warned
|
|
|
|
# about that job and are told to type `exit` a second time.
|
|
|
|
send("sleep 111 &\r")
|
|
|
|
expect_prompt()
|
|
|
|
send("exit\r")
|
2020-06-08 15:32:56 +00:00
|
|
|
expect_re(
|
|
|
|
"""There are still jobs active:\r
|
2020-06-08 15:31:18 +00:00
|
|
|
\r
|
|
|
|
PID Command\r
|
|
|
|
*\\d+ sleep 111 &\r
|
|
|
|
\r
|
|
|
|
A second attempt to exit will terminate them.\r
|
2020-06-08 15:32:56 +00:00
|
|
|
Use 'disown PID' to remove jobs from the list without terminating them.\r"""
|
|
|
|
)
|
2020-06-08 15:31:18 +00:00
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# Running anything other than `exit` should result in the same warning with
|
|
|
|
# the shell still running.
|
|
|
|
send("sleep 113 &\r")
|
|
|
|
expect_prompt()
|
|
|
|
send("exit\r")
|
2020-06-08 15:32:56 +00:00
|
|
|
expect_re(
|
|
|
|
"""There are still jobs active:\r
|
2020-06-08 15:31:18 +00:00
|
|
|
\r
|
|
|
|
PID Command\r
|
|
|
|
*\\d+ sleep 113 &\r
|
|
|
|
*\\d+ sleep 111 &\r
|
|
|
|
\r
|
|
|
|
A second attempt to exit will terminate them.\r
|
2020-06-08 15:32:56 +00:00
|
|
|
Use 'disown PID' to remove jobs from the list without terminating them.\r"""
|
|
|
|
)
|
2020-06-08 15:31:18 +00:00
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# Verify that asking to exit a second time does so.
|
|
|
|
send("exit\r")
|
|
|
|
|
2020-11-22 13:39:48 +00:00
|
|
|
for t in range(0, 3):
|
2020-08-08 14:06:11 +00:00
|
|
|
proc = subprocess.run(
|
2020-11-22 13:39:48 +00:00
|
|
|
["pgrep", "-l", "-f", "sleep 11"],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
2020-08-08 14:06:11 +00:00
|
|
|
)
|
|
|
|
if proc.returncode != 0:
|
|
|
|
break
|
|
|
|
# This is cheesy, but on Travis with thread-sanitizer this can be slow enough that the process is still running, so we sleep for a bit.
|
|
|
|
time.sleep(1)
|
|
|
|
else:
|
2020-06-08 15:31:18 +00:00
|
|
|
print("Commands still running")
|
|
|
|
print(proc.stdout)
|
|
|
|
sys.exit(1)
|