Skip to content

Commit 050d877

Browse files
committed
Improve test bash script behavior.
1 parent 27a806e commit 050d877

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

testdata/output/ping.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
#!/bin/bash
2+
ready=0
23
count=0
34
trap sigusr1_handler SIGUSR1
5+
trap sigusr2_handler SIGUSR2
46

57
function sigusr1_handler() {
6-
stdbuf -o0 echo "PONG $((++count))"
7-
stdbuf -o0 kill -SIGUSR1 $pids 2>/dev/null
8+
((ready = 1))
9+
}
10+
11+
function sigusr2_handler() {
12+
((count++))
13+
stdbuf -o0 echo "PONG $count"
14+
if [ $count -lt 10 ]; then
15+
stdbuf -o0 kill -SIGUSR2 $pids 2>/dev/null
16+
fi
817
}
918

1019
while [[ -z $pids ]]
1120
do
1221
pids=$(ps -ef | grep pong.sh | grep -v grep | awk '{print $2}')
1322
sleep 0.001
1423
done
15-
16-
kill -SIGUSR1 $pids 2>/dev/null
24+
25+
while [[ $ready == 0 ]]
26+
do
27+
stdbuf -o0 kill -SIGUSR1 $pids 2>/dev/null
28+
sleep 0.001
29+
done
30+
31+
stdbuf -o0 kill -SIGUSR2 $pids 2>/dev/null
1732
while [[ $count -lt 10 ]]; do
1833
sleep 0.001
1934
done

testdata/output/pong.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
#!/bin/bash
2+
ready=0
23
count=0
34
trap sigusr1_handler SIGUSR1
5+
trap sigusr2_handler SIGUSR2
46

57
function sigusr1_handler() {
6-
stdbuf -o0 echo "PING $((++count))"
7-
stdbuf -o0 kill -SIGUSR1 $pids 2>/dev/null
8+
((ready = 1))
9+
}
10+
11+
function sigusr2_handler() {
12+
((count++))
13+
stdbuf -o0 echo "PING $count"
14+
if [ $count -lt 11 ]; then
15+
stdbuf -o0 kill -SIGUSR2 $pids 2>/dev/null
16+
fi
817
}
918

1019
while [[ -z $pids ]]
1120
do
1221
pids=$(ps -ef | grep ping.sh | grep -v grep | awk '{print $2}')
1322
sleep 0.001
1423
done
24+
25+
while [[ $ready == 0 ]]
26+
do
27+
stdbuf -o0 kill -SIGUSR1 $pids 2>/dev/null
28+
sleep 0.001
29+
done
1530

1631
while [[ $count -lt 10 ]]; do
1732
sleep 0.001

0 commit comments

Comments
 (0)