summaryrefslogtreecommitdiffstats
path: root/tests/rcvr_fail_restore.sh
blob: 53dd89158914359b88a5d5a4e6726b9a132c74e9 (plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# Copyright (C) 2011 by Rainer Gerhards
# This file is part of the rsyslog project, released under ASL 2.0
. ${srcdir:=.}/diag.sh init
skip_platform "FreeBSD"  "This test does not work on FreeBSD - problems with os utility option switches"
#
# STEP1: start both instances and send 1000 messages.
# Note: receiver is instance 1, sender instance 2.
#
# start up the instances. Note that the environment settings can be changed to
# set instance-specific debugging parameters!
#export RSYSLOG_DEBUG="debug nostdout"
#export RSYSLOG_DEBUGLOG="log2"
echo starting receiver
generate_conf
add_conf '
# then SENDER sends to this port (not tcpflood!)
module(load="../plugins/imtcp/.libs/imtcp")
input(type="imtcp" port="0" listenPortFileName="'$RSYSLOG_DYNNAME'.tcpflood_port" )

$template outfmt,"%msg:F,58:2%\n"
:msg, contains, "msgnum:" ./'$RSYSLOG_OUT_LOG';outfmt
'
startup
export PORT_RCVR="$TCPFLOOD_PORT"
#export RSYSLOG_DEBUG="debug nostdout"
#export RSYSLOG_DEBUGLOG="log"
#valgrind="valgrind"
echo starting sender
generate_conf 2
export TCPFLOOD_PORT="$(get_free_port)"
add_conf '
$WorkDirectory '$RSYSLOG_DYNNAME'.spool
$MainMsgQueueSize 2000
$MainMsgQueueLowWaterMark 800
$MainMsgQueueHighWaterMark 1000
$MainMsgQueueDequeueBatchSize 1
$MainMsgQueueMaxFileSize 1g
$MainMsgQueueWorkerThreads 1
$MainMsgQueueFileName mainq

# we use the shortest resume interval a) to let the test not run too long 
# and b) make sure some retries happen before the reconnect
$ActionResumeInterval 1
$ActionSendResendLastMsgOnReconnect on
$ActionResumeRetryCount -1
*.*	@@127.0.0.1:'$PORT_RCVR'
' 2
startup 2
# re-set params so that new instances do not thrash it...
#unset RSYSLOG_DEBUG
#unset RSYSLOG_DEBUGLOG

# now inject the messages into instance 2. It will connect to instance 1,
# and that instance will record the data.
injectmsg2  1 1000
wait_queueempty
./msleep 1000 # let things settle down a bit

#
# Step 2: shutdown receiver, then send some more data, which then
# needs to go into the queue.
#
echo step 2

shutdown_when_empty
wait_shutdown

injectmsg2  1001 10000
./msleep 3000 # make sure some retries happen (retry interval is set to 3 second)
get_mainqueuesize 2
ls -l ${RSYSLOG_DYNNAME}.spool

#
# Step 3: restart receiver, wait that the sender drains its queue
$InputTCPServerRun '$PORT_RCVR'
#
echo step 3
#export RSYSLOG_DEBUGLOG="log2"
generate_conf
add_conf '
# then SENDER sends to this port (not tcpflood!)
module(load="../plugins/imtcp/.libs/imtcp")
input(type="imtcp" port="'$PORT_RCVR'")

$template outfmt,"%msg:F,58:2%\n"
:msg, contains, "msgnum:" ./'$RSYSLOG_OUT_LOG';outfmt
'
startup
echo waiting for sender to drain queue [may need a short while]
wait_queueempty 2
ls -l ${RSYSLOG_DYNNAME}.spool
OLDFILESIZE=$(stat -c%s ${RSYSLOG_DYNNAME}.spool/mainq.00000001)
echo file size to expect is $OLDFILESIZE


#
# Step 4: send new data. Queue files are not permitted to grow now
# (but one file continuous to exist).
#
echo step 4
injectmsg2  11001 10
wait_queueempty 2

# at this point, the queue file shall not have grown. Note
# that we MUST NOT shut down the instance right now, because it
# would clean up the queue files! So we need to do our checks
# first (here!).
ls -l ${RSYSLOG_DYNNAME}.spool
NEWFILESIZE=$(stat -c%s ${RSYSLOG_DYNNAME}.spool/mainq.00000001)
if [ $NEWFILESIZE != $OLDFILESIZE ]
then
   echo file sizes do not match, expected $OLDFILESIZE, actual $NEWFILESIZE
   echo this means that data has been written to the queue file where it
   echo no longer should be written.
   # abort will happen below, because we must ensure proper system shutdown
   # HOWEVER, during actual testing it may be useful to do an exit here (so
   # that e.g. the debug log is pointed right at the correct spot).
   # exit 1
fi

#
# We now do an extra test (so this is two in one ;)) to see if the DA
# queue can be reactivated after its initial shutdown. In essence, we 
# redo steps 2 and 3.
#
# Step 5: stop receiver again, then send some more data, which then
# needs to go into the queue.
#
echo step 5
echo "*** done primary test *** now checking if DA can be restarted"
shutdown_when_empty
wait_shutdown

injectmsg2  11011 10000
sleep 1 # we need to wait, otherwise we may be so fast that the receiver
# comes up before we have finally suspended the action
get_mainqueuesize 2
ls -l ${RSYSLOG_DYNNAME}.spool

#
# Step 6: restart receiver, wait that the sender drains its queue
#
echo step 6
startup
echo waiting for sender to drain queue [may need a short while]
wait_queueempty 2
ls -l ${RSYSLOG_DYNNAME}.spool

#
# Queue file size checks done. Now it is time to terminate the system
# and see if everything could be received (the usual check, done here
# for completeness, more or less as a bonus).
#
shutdown_when_empty 2
wait_shutdown 2

# now it is time to stop the receiver as well
shutdown_when_empty
wait_shutdown

# now abort test if we need to (due to filesize predicate)
if [ $NEWFILESIZE != $OLDFILESIZE ]; then
	error_exit 1
fi
# do the final check
seq_check 1 21010 -m 100
exit_test