File: wait.py

package info (click to toggle)
fish 4.2.1-3.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,976 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (131 lines) | stat: -rw-r--r-- 3,378 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
from pexpect_helper import SpawnedProc

import os
import sys

# Disable under SAN - keeps failing because the timing is too tight
if "FISH_CI_SAN" in os.environ:
    sys.exit(0)

sp = SpawnedProc()
send, sendline, sleep, expect_prompt, expect_re, expect_str = (
    sp.send,
    sp.sendline,
    sp.sleep,
    sp.expect_prompt,
    sp.expect_re,
    sp.expect_str,
)
expect_prompt()

# one background job
sendline("sleep .3 &")
expect_prompt()
sendline("wait")
expect_prompt("Job 1, 'sleep .3 &' has ended")
sendline("jobs")
expect_prompt("jobs: There are no jobs")

# three job ids specified
sendline("sleep 0.5 &; sleep 0.1 &; sleep 0.3 &; sleep 0.7 &; wait %1 %3 %4")
expect_str("Job 2, 'sleep 0.1 &' has ended")
expect_str("Job 3, 'sleep 0.3 &' has ended")
expect_str("Job 1, 'sleep 0.5 &' has ended")
expect_prompt("Job 4, 'sleep 0.7 &' has ended")
sendline("jobs")
expect_prompt("jobs: There are no jobs")

# specify job ids with -n option
sendline("sleep 0.5 &; sleep 0.1 &; sleep 0.3 &; wait -n %1 %3")
expect_str("Job 2, 'sleep 0.1 &' has ended")
expect_prompt("Job 3, 'sleep 0.3 &' has ended")
sendline("wait -n %1")
expect_prompt("Job 1, 'sleep 0.5 &' has ended")
sendline("jobs")
expect_prompt("jobs: There are no jobs")

# don't wait for stopped jobs
sendline("sleep 0.3 &")
expect_prompt()
sendline("kill -STOP %1")
expect_prompt()
sendline("wait")
expect_prompt()
sendline("wait %1")
expect_prompt()
sendline("wait -n")
expect_prompt()
sendline("bg %1")
expect_prompt()
sendline("wait")
expect_prompt()
sendline("jobs")
expect_prompt("jobs: There are no jobs")

sendline(
    "sleep .3 &; kill -STOP %1; kill -CONT %1; jobs | string match -r running; wait"
)
expect_prompt("running")

# return immediately when no jobs
sendline("wait")
expect_prompt()
sendline("wait -n")
expect_prompt()
sendline("jobs")
expect_prompt("jobs: There are no jobs")

# wait for jobs by its process name with -n option
sendline("for i in (seq 1 3); sleep 0.$i &; end")
expect_prompt()
sendline("wait -n sleep")
expect_prompt()
sendline("jobs | wc -l")
expect_str("2")
expect_prompt()
sendline("wait")
expect_prompt()
sendline("jobs")
expect_prompt("jobs: There are no jobs")

# complex case
sendline("for i in (seq 1 10); ls | sleep 0.2 | cat > /dev/null &; end")
expect_prompt()
sendline("sleep 0.3 | cat &")
expect_prompt()
sendline("sleep 0.1 &")
expect_prompt()
sendline("wait $last_pid sleep")
expect_prompt()
sendline("jobs")
expect_prompt("jobs: There are no jobs")

# don't wait for itself
sendline("wait wait")
expect_prompt("wait: Could not find child processes with the name 'wait'")
sendline("wait -n wait")
expect_prompt("wait: Could not find child processes with the name 'wait'")
sendline("jobs")
expect_prompt("jobs: There are no jobs")

# test with fish script
sendline("fish -c 'sleep 0.2 &; sleep 0.3 &; sleep 0.1 &; wait -n sleep; jobs | wc -l'")
expect_str("1")
expect_prompt()

# test error messages
sendline("wait 0")
expect_prompt("wait: '0' is not a valid process ID")
sendline("wait 1")
expect_prompt("wait: Could not find a job with process ID '1'")
sendline("wait hoge")
expect_prompt("wait: Could not find child processes with the name 'hoge'")

# See that we don't wait if job expansion fails
sendline("sleep 5m &")
expect_prompt()
sendline("wait %5")
expect_prompt("jobs: No suitable job: %5")
sendline("kill %1")
expect_prompt()