testbench: try to reproduce imfile "file no longer monitored" error

see also https://github.com/rsyslog/rsyslog/issues/1605
This commit is contained in:
Rainer Gerhards 2018-09-10 14:36:12 +02:00
parent 2d15cbc822
commit 8c7718d34f
3 changed files with 60 additions and 3 deletions

View File

@ -583,9 +583,9 @@ strmHandleEOFMonitor(strm_t *pThis)
ISOBJ_TYPE_assert(pThis, strm);
if(stat((char*) pThis->pszCurrFName, &statName) == -1)
ABORT_FINALIZE(RS_RET_IO_ERROR);
DBGPRINTF("stream checking for file change on '%s', inode %u/%u\n",
pThis->pszCurrFName, (unsigned) pThis->inode,
(unsigned) statName.st_ino);
DBGPRINTF("stream checking for file change on '%s', inode %u/%u size %llu/%llu\n",
pThis->pszCurrFName, (unsigned) pThis->inode, (unsigned) statName.st_ino,
(long long unsigned) pThis->iCurrOffs, (long long unsigned) statName.st_size);
/* Inode unchanged but file size on disk is less than current offset
* means file was truncated, we also reopen if 'reopenOnTruncate' is on

View File

@ -947,6 +947,7 @@ TESTS += \
imfile-fileNotFoundError-parameter.sh \
imfile-error-not-repeated.sh \
imfile-truncate.sh \
imfile-truncate-multiple.sh \
imfile-readmode2.sh \
imfile-readmode2-polling.sh \
imfile-readmode2-with-persists-data-during-stop.sh \
@ -1553,6 +1554,7 @@ EXTRA_DIST= \
imfile-freshStartTail2.sh \
imfile-freshStartTail3.sh \
imfile-truncate.sh \
imfile-truncate-multiple.sh \
imfile-wildcards.sh \
imfile-wildcards-dirs.sh \
imfile-wildcards-dirs2.sh \

View File

@ -0,0 +1,55 @@
#!/bin/bash
# this test checks truncation mode, and does so with multiple truncations of
# the input file.
# It also needs a larger load, which shall be sufficient to do begin of file
# checks as well as should support file id hash generation.
# addd 2016-10-06 by RGerhards, released under ASL 2.0
. $srcdir/diag.sh init
. $srcdir/diag.sh check-inotify
export RSYSLOG_DEBUG="debug nologfuncflow noprintmutexaction nostdout"
export RSYSLOG_DEBUGLOG="log"
generate_conf
add_conf '
module(load="../plugins/imfile/.libs/imfile" pollingInterval="1")
input(type="imfile" File="'./$RSYSLOG_DYNNAME'.input" Tag="file:" reopenOnTruncate="on")
template(name="outfmt" type="string" string="%msg:F,58:2%\n")
if $msg contains "msgnum:" then
action( type="omfile" file=`echo $RSYSLOG_OUT_LOG` template="outfmt")
'
# write the beginning of the file
NUMMSG=1000
./inputfilegen -m 1000 -i0 > $RSYSLOG_DYNNAME.input
ls -li $RSYSLOG_DYNNAME.input
inode=$(ls -i $RSYSLOG_DYNNAME.input | awk '{ print $1;}' )
echo inode $inode
startup
for i in {0..50}; do
# check that previous msg injection worked
wait_queueempty
echo nbr of lines: $(wc -l $RSYSLOG_OUT_LOG)
seq_check 0 $((NUMMSG - 1))
# begin new inject cycle
generate_msgs=$(( i * 50))
echo generating $NUMMSG .. $((NUMMSG + generate_msgs -1))
./inputfilegen -m$generate_msgs -i$NUMMSG > $RSYSLOG_DYNNAME.input
let NUMMSG=NUMMSG+generate_msgs
if [ $inode -ne $(ls -i $RSYSLOG_DYNNAME.input | awk '{ print $1;}' ) ]; then
echo FAIL testbench did not keep same inode number, expected $inode
ls -li $RSYSLOG_DYNNAME.input
exit 100
fi
done
echo generated $NUMMSG messages
shutdown_when_empty
wait_shutdown
seq_check 0 $((NUMMSG - 1))
exit_test