Add fsync options.
[beanstalkd.git] / sh-tests / binlog-sizelimit.sh
blobddc2eeb3e4fe7aa1cd6e7fc3024e039aa0bf38d1
1 #!/usr/bin/env bash
3 server=localhost
4 port=11400
5 tmpdir="$TMPDIR"
6 size=1000
7 test -z "$tmpdir" && tmpdir=/tmp
8 out1="${tmpdir}/bnch$$.1"
9 out2="${tmpdir}/bnch$$.2"
10 logdir="${tmpdir}/bnch$$.d"
11 nc='nc -q 1'
12 nc -q 1 2>&1 | grep -q option && nc='nc -w 1' # workaround for older netcat
14 killbeanstalkd() {
16 test -z "$bpid" || kill -9 $bpid
17 /bin/true # Somehow this gets rid of an unnessary shell message.
18 } >/dev/null 2>&1
19 bpid=
22 cleanup() {
23 killbeanstalkd
24 rm -rf "$logdir" "$out1" "$out2"
27 catch() {
28 echo '' Interrupted
29 exit 3
32 trap cleanup EXIT
33 trap catch HUP INT QUIT TERM
35 if [ ! -x ./beanstalkd ]; then
36 echo "Executable ./beanstalkd not found; do you need to compile first?"
37 exit 2
40 mkdir -p $logdir
42 ./beanstalkd -p $port -b "$logdir" -s $size >/dev/null 2>/dev/null &
43 bpid=$!
45 sleep .1
46 if ! ps -p $bpid >/dev/null; then
47 echo "Could not start beanstalkd for testing (possibly port $port is taken)"
48 exit 2
51 # Check that the first binlog file is the proper size.
52 test "$(stat --printf=%s "$logdir"/binlog.1)" -eq $size || exit 1
54 # Insert enough jobs to create a second binlog file
55 $nc $server $port <<EOF > "$out1"
56 put 0 0 100 50
57 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
58 put 0 0 100 50
59 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
60 put 0 0 100 50
61 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
62 put 0 0 100 50
63 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
64 put 0 0 100 50
65 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
66 put 0 0 100 50
67 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
68 put 0 0 100 50
69 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
70 put 0 0 100 50
71 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
72 put 0 0 100 50
73 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
74 put 0 0 100 50
75 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
76 put 0 0 100 50
77 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
78 put 0 0 100 50
79 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
80 put 0 0 100 50
81 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
82 put 0 0 100 50
83 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
84 put 0 0 100 50
85 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
86 put 0 0 100 50
87 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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 EOF
98 diff - "$out1" <<EOF
99 INSERTED 1
100 INSERTED 2
101 INSERTED 3
102 INSERTED 4
103 INSERTED 5
104 INSERTED 6
105 INSERTED 7
106 INSERTED 8
107 INSERTED 9
108 INSERTED 10
109 INSERTED 11
110 INSERTED 12
111 INSERTED 13
112 INSERTED 14
113 INSERTED 15
114 INSERTED 16
115 INSERTED 17
116 INSERTED 18
117 INSERTED 19
118 INSERTED 20
120 res=$?
121 test "$res" -eq 0 || exit $res
123 # Check that the first binlog file is still the proper size.
124 test "$(stat --printf=%s "$logdir"/binlog.1)" -eq $size || exit 1
126 # Check that the second binlog file is the proper size.
127 test "$(stat --printf=%s "$logdir"/binlog.2)" -eq $size || exit 1
129 killbeanstalkd