EPOLLRDHUP was introduced in Linux 2.6.17.
[beanstalkd.git] / sh-tests / binlog-diskfull-delete.sh
blobf2a65259359dfb29f09be864bf3f3424c2fbbfdb
1 #!/usr/bin/env bash
3 . "sh-tests/common.functions"
5 ENOSPC=28
6 server=localhost
7 tmpdir="$TMPDIR"
8 size=1000
9 test -z "$tmpdir" && tmpdir=/tmp
10 out1="${tmpdir}/bnch$$.1"
11 out2="${tmpdir}/bnch$$.2"
12 logdir="${tmpdir}/bnch$$.d"
13 nc="sh-tests/netcat.py"
15 if test "`type -t fiu-run`" = ''
16 then
17 echo ...skipped. '(requires fiu tools from http://blitiri.com.ar/p/libfiu/)'
18 exit 0
21 fail() {
22 printf 'On line '
23 caller
24 echo ' ' "$@"
25 exit 1
28 cleanup() {
29 killbeanstalkd
30 rm -rf "$logdir" "$out1" "$out2" ${tmpdir}/fiu-ctrl-[0-9]*.{in,out}
33 catch() {
34 echo '' Interrupted
35 exit 3
38 # Yuck.
39 fsize() {
40 ls -l -- "$@" | awk '{ print $5 }'
43 trap cleanup EXIT
44 trap catch HUP INT QUIT TERM
46 if [ ! -x ./beanstalkd ]; then
47 echo "Executable ./beanstalkd not found; do you need to compile first?"
48 exit 2
51 start_beanstalkd $logdir "-s $size" "fiu-run -x"
53 # Insert enough jobs to create another binlog file
54 $nc $server $port <<EOF > "$out1"
55 put 0 0 100 50
56 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
57 put 0 0 100 50
58 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
59 put 0 0 100 50
60 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
61 put 0 0 100 50
62 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
63 put 0 0 100 50
64 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
65 quit
66 EOF
68 diff - "$out1" <<EOF
69 INSERTED 1
70 INSERTED 2
71 INSERTED 3
72 INSERTED 4
73 INSERTED 5
74 EOF
75 res=$?
76 test "$res" -eq 0 || exit $res
78 # Check that the second binlog file is present
79 test "$(fsize "$logdir"/binlog.2)" -eq $size || {
80 fail Second binlog file is missing
83 # Make beanstalkd think the disk is full now.
84 fiu-ctrl -e posix/io/oc/open -i $ENOSPC $bpid
86 # Insert enough jobs to create another binlog file
87 $nc $server $port <<EOF > "$out1"
88 put 0 0 100 50
89 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
90 put 0 0 100 50
91 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
92 put 0 0 100 50
93 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
94 put 0 0 100 50
95 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
96 put 0 0 100 50
97 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
98 quit
99 EOF
101 diff - "$out1" <<EOF
102 INSERTED 6
103 INSERTED 7
104 INSERTED 8
105 OUT_OF_MEMORY
106 OUT_OF_MEMORY
108 res=$?
109 test "$res" -eq 0 || exit $res
111 # Check that the first binlog file is still there
112 test -e "$logdir"/binlog.1 || fail First binlog file is missing
114 $nc $server $port <<EOF > "$out1"
115 delete 1
116 delete 2
117 delete 3
118 delete 4
119 delete 5
120 delete 6
121 delete 7
122 quit
125 diff - "$out1" <<EOF
126 DELETED
127 DELETED
128 DELETED
129 DELETED
130 DELETED
131 DELETED
132 DELETED
134 res=$?
135 test "$res" -eq 0 || exit $res
137 # Check that the first binlog file was deleted
138 test ! -e "$logdir"/binlog.1 || fail First binlog file is still there
140 # Now make beanstalkd think the disk once again has space.
141 fiu-ctrl -d posix/io/oc/open $bpid
143 # Insert enough jobs to create another binlog file
144 $nc $server $port <<EOF > "$out1"
145 put 0 0 100 50
146 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
147 put 0 0 100 50
148 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
149 put 0 0 100 50
150 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
151 put 0 0 100 50
152 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
153 quit
156 diff - "$out1" <<EOF
157 INSERTED 11
158 INSERTED 12
159 INSERTED 13
160 INSERTED 14
162 res=$?
163 test "$res" -eq 0 || exit $res
165 killbeanstalkd
167 start_beanstalkd $logdir "-s $size"
169 $nc $server $port <<EOF > "$out2"
170 delete 8
171 delete 11
172 delete 12
173 delete 13
174 delete 14
175 quit
178 diff - "$out2" <<EOF
179 DELETED
180 DELETED
181 DELETED
182 DELETED
183 DELETED